Get-Aduser -Filter will not accept a variable

前端 未结 7 791
挽巷
挽巷 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:32

    Simply remove the quotes around your variable:

    $SamAc = Read-Host 'What is your username?'

    $User = Get-ADUser -Filter {sAMAccountName -eq $SamAc}

    This should work just fine.

提交回复
热议问题