Get-Aduser -Filter will not accept a variable

前端 未结 7 969
挽巷
挽巷 2020-11-22 02:09

I\'d like to check if a user account already exists in the system.

$SamAc = Read-Host \'What is your username?\'
$User = Get-ADUser -Filter {sAMAccountName -         


        
7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-22 02:28

    if (($ADUser = Get-ADUser -filter "SamAccountName -eq '$(Read-Host Username)'") -ne $null) {$ADUser.SamAccountName} else {"Not Found"}
    

提交回复
热议问题