Get-ADComputer : Cannot validate argument on parameter 'Identity'

Welcome Forums General PowerShell Q&A Get-ADComputer : Cannot validate argument on parameter 'Identity'

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
1 year, 7 months ago.

  • Author
    Posts
  • #69214

    Participant
    Points: 71
    Rank: Member

    Hello,

    I guess I am not understanding ForEach as I get this error:

    Import-Csv C:\temp\XP_disable\computers.csv
    ForEach-Object {
        Get-ADComputer -identity $_.Name
    }

    ERROR:

    Get-ADComputer : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and 
    then try running the command again.

    Is the issue that import-csv is throwing away some object?

  • #69217

    Participant
    Points: 0
    Rank: Member

    If you code is exactly as posted nothing is being sent to ForEach-Object so $_.Name will be empty.
    Instead try:

    Import-Csv C:\temp\XP_disable\computers.csv | ForEach-Object { Get-ADComputer -identity $_.Name }
    

    This will send the output of Import-Csv over the pipeline (the "|" or pipe) to ForEach-Object ensuing that $_.Name will be populated.

    • #69229

      Participant
      Points: 71
      Rank: Member

      Ah! thanks Dakota...Appreciate the second pair of eyes

The topic ‘Get-ADComputer : Cannot validate argument on parameter 'Identity'’ is closed to new replies.