Invoke-Command: Cannot Validate argument on parameter. The argument is null or empty

JKFrancis 76 Reputation points
2021-07-12T18:05:06.883+00:00

I am trying to get the list of computers with their powershell version and I get an error in Powershell. Not sure where I am doing wrong?

$Adcomputerlist = Get-Content c:\adcomputerlist.txt
Invoke-Command -ComputerName $Adcomputerlist -Scriptblock { $PSVersionTable.PSVersion } -ErrorAction SilentlyContinue |
Select-Object -Property PSComputerName,Major,Minor,Build,Revision |
Export-CSV -Path c:\PSVersionsresult.csv -NoTypeInformation -Delimiter ','

The error is as follows below:

Invoke-Command : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At C:\Users\Ops081\Documents\Powershell Scripts\GetPowershellversions7122021.ps1:12 char:30

  • Invoke-Command -ComputerName $adcomputerList -Scriptblock { $PSVersi ...
  • ~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
  • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 45,096 Reputation points
    2021-07-12T18:28:02.24+00:00

    Have you verified that $AdcomputerList has been populated?

    1 person found this answer helpful.
    0 comments No comments

  2. Ian Xue (Shanghai Wicresoft Co., Ltd.) 30,376 Reputation points Microsoft Vendor
    2021-07-13T05:53:17.77+00:00

    Hi,

    The variable $Adcomputerlist is null. Is the file c:\adcomputerlist.txt empty?

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments