Get-ADUser : Cannot validate argument on parameter 'Identity' Any Idea why ?

$users = Get-Content C:\users\mrk\desktop\users.txt

foreach($i in $users){

Get-ADUser -Identity “$i” | select name, Enabled

Whatever is in variable $i is making it angry.

$i should have one user from $users for every loop, not sure why it says null.

Get-ADUser : Cannot validate argument on parameter ‘Identity’. The Identity property on the
argument is null or empty.
At line:6 char:31

  • $c = Get-ADUser -Identity "$i" | select Enabled, name
  •                           ~~~~
    • CategoryInfo : InvalidData: (:slight_smile: [Get-ADUser], ParameterBindingValidationExcept
    • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Mana

Try outputting the contents of $i.

I’ve found in some cases you get a blank line in the text file where you don’t realize it. That’ll bork it up.

$users = Get-Content C:\users\mrk\desktop\trim.txt

foreach($i in $users){

Write-Host $i
$c = Get-ADUser -Identity “$i” | select Enabled, name


I tried this, I get a list of users on the console but the error remains the same.


Write-Host " - $i -"

Just to make sure you’re not getting a blank line and not noticing. Other than that, it’s just some value that AD is rejecting.

I have messed up some basics here and fixed it now :slight_smile: Thankyou @DonJones “The PowerShell Master”