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

JKFrancis 56 Reputation points

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,168 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 42,826 Reputation points

    Have you verified that $AdcomputerList has been populated?

    0 comments No comments

  2. Ian Xue (Shanghai Wicresoft Co., Ltd.) 24,281 Reputation points Microsoft Vendor


    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