question

JKFrancis avatar image
0 Votes"
JKFrancis asked IanXue-MSFT answered

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

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Have you verified that $AdcomputerList has been populated?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.