skip to Main Content

When using Visual Studio Code and PSverion 7.2.6 I am no longer able to use a variable in Get-ADUser Filter.
Command:

Get-ADUser -server $DC  -Filter 'sAMAccountName -eq $Input'  -Properties $sProperties  | Select $sProperties

getting this error:
Get-ADUser: Variable: ‘Input’ found in expression: $Input is not defined.

That works fine in PowerShell ISE ver 5.1.

2

Answers


  1. Chosen as BEST ANSWER

    I played with the quotation marks ("sAMAccountName -eq 'Input'") and found the solution:

    Get-ADUser -server $DC  -Filter "sAMAccountName -eq '$ReadInput'"  -Properties $sProperties  | Select $sProperties
    

  2. try this

    Get-ADUser -server $DC  -Filter "sAMAccountName -eq '$($Input)'"  -Properties $sProperties  | Select $sProperties
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search