Quantcast
Channel: Active questions tagged powershell-3.0 - Stack Overflow
Viewing all articles
Browse latest Browse all 122

Get-Aduser -Filter will not accept a variable

$
0
0

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 -eq "$SamAc"}

I'm not sure why, but $User will always return null even if {sAMAccountName -eq "$SamAc"} is supposed to be true.

What am I missing here?

Edit:

This is what was missing:

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

Editor's note: The script block ({ ... }) was replaced with a string.


Viewing all articles
Browse latest Browse all 122

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>