0
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.

2
  • $user -eq $null is the test for if the user has not entered credentials. !() reverses it. So you are looping while the user HAS entered credentials. Remove the ! Commented Mar 7, 2018 at 9:55
  • Thanks !! How I can make such a mistake lol Commented Mar 7, 2018 at 9:57

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.