ISSUE:
My issue is that I have a very simple do..while
loop. However, it does not print the output of the Get-ADPrincipalGroupMembership
query on the first iteration. For example, I run the script and enter a username then click enter. Instead of my expected result which is print the memberships, it loops around and asks for username again without printing the results of the first inputted username. Once I enter the username the second time in the loop and click enter then it prints the results of the first input and the results of the second input. Any time after the second iteration the script works fine and actually prints the results correctly after I provide the input. Below is the script in question.
EXPECTED RESULT:
The code below is simply supposed to ask the user for a username then run a query in AD to list the memberships of a given user. After providing the memberships of a user the script should ask for another user and repeat the process until the user enters "exit" and the script exits out.
CODE SNIPPET:
do {
$user = Read-Host -Prompt 'Enter the username of the user';
Get-ADPrincipalGroupMembership $user | select name;
} while ($user -ne 'exit');
Stop-Process -Id $PID;