Reputation: 35
do {
$user = $null
Write-Host "Please enter your credentials in order to connect you to the Azure AD."
$user = Get-Credential
if ($user -eq $null) {
Write-Host "Bad credentials. Please retry."
}
} while (!($user -eq $null))
This part of the script will allow the user to enter his credentials. I wanted to check if the user inputs something.
Problem is, if the user does not input something, the script works well and the user is forced to enter credentials.
But when I input something, I don't have any errors, but the script loops! It doesn't want to exit the loop.
Where am I wrong?
I've also tried
while ($user -eq $true)
but it doesn't work either. The user, even if he doesn't enter something, passed the while.
Upvotes: 0
Views: 1826
Reputation: 200193
Your loop continues as long as the user provides credentials ($user
is not $null
). You want to loop as long as the user does not provide credentials ($user
is $null
).
do {
...
} while ($user -eq $null)
Upvotes: 2