我正在尝试使用samaccountname在AD中找到特定用户如果我输入的帐户不正确,我希望问题重复,直到找到用户,告诉我用户名并暂停直到按下某个键。以下是我到目前为止所做的工作。我仍然是一个菜鸟。
do{
$User=Read-Host "Enter SamAcountname"}
if (dsquery user -samid $User)
{
trap {$_ | write-host "Found user $_"
}
else
{
trap {$_ | write-host "User not found!"
}
{
until ( $_-eq "found user")
}
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
答案 0 :(得分:0)
这应该这样做:
$prompt = "enter samaccountname"
do{
$User = Read-Host $prompt
} while (!$(dsquery user -samid $User;$prompt="User '$user' was not found, try again"))
$User