Tihomir Buncic
Tihomir Buncic

Reputation: 35

Using a variable in Get-ADUser -Filter - PowerShell version 7

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.

Upvotes: 1

Views: 1139

Answers (2)

Tihomir Buncic
Tihomir Buncic

Reputation: 35

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

Upvotes: 1

victorR
victorR

Reputation: 139

try this

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

Upvotes: -1

Related Questions