Get-Aduser -Filter will not accept a variable

前端 未结 7 779
挽巷
挽巷 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:42

    Okay, I got mine to finally work using the following syntax and using the following example from up above:

    Previously:

    $User = Get-ADUser -Filter "sAMAccountName -eq '$SamAc'"
    

    Working Version:

    $user = Get-aduser -Filter "sAMAccountName -eq '$($SamAc)'"
    

    I had to add $($ ) to $SamAc before PowerShell could access the variable string value.

提交回复
热议问题