0

我正在尝试使用 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")
4

1 回答 1

0

这应该这样做:

$prompt = "enter samaccountname"

do{    
    $User = Read-Host $prompt
} while (!$(dsquery user -samid $User;$prompt="User '$user' was not found, try again"))

$User
于 2013-06-10T19:49:23.023 回答