Author Posts

June 7, 2018 at 4:11 pm

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

foreach($i in $users){

Get-ADUser -Identity "$i" | select name, Enabled

June 7, 2018 at 4:12 pm

Whatever is in variable $i is making it angry.

June 7, 2018 at 4:15 pm

$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: (:) [Get-ADUser], ParameterBindingValidationExcept
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Mana

June 7, 2018 at 4:16 pm

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.

June 7, 2018 at 4:19 pm

$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.

June 7, 2018 at 4:23 pm


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.

June 7, 2018 at 4:31 pm

I have messed up some basics here and fixed it now 🙂 Thankyou @DonJones "The PowerShell Master"