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

This topic contains 6 replies, has 2 voices, and was last updated by  Mallik 1 week, 6 days ago.

  • Author
    Posts
  • #102023

    Mallik
    Participant

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

    foreach($i in $users){

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

  • #102025

    Don Jones
    Keymaster

    Whatever is in variable $i is making it angry.

  • #102026

    Mallik
    Participant

    $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
    ion
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Mana
    gement.Commands.GetADUser

  • #102028

    Don Jones
    Keymaster

    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.

  • #102031

    Mallik
    Participant

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

  • #102034

    Don Jones
    Keymaster

    Try

    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.

  • #102040

    Mallik
    Participant

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

You must be logged in to reply to this topic.