문제

Im trying to create a while loop that request the correct user input before the script continues.

What I wan't is to make while loop that runs if the value is NOT true. So if the user doens't exist the while loop ask for a new username but i can't figure out how to do this. Se the example down below that works if the user exists. I have tried -ne $true and -not i different ways without success.

while(Get-ADUser -Identity USERNAME)
{
Read-host "Please enter a existing user"
}
도움이 되었습니까?

해결책

do
{
    $username = Read-host "Please enter an existing username"
} while ($username -eq "" -or (Get-ADUser -Filter {Name -eq $username}) -eq $null)

This is case insensitive though. This one might work better:

do
{
    $username = Read-host "Please enter an existing username"
} while ($username -eq "" -or (Get-ADUser -Filter "Name -like `"$username`"") -eq $null)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top