Have you verified that $AdcomputerList has been populated?
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
2 answers
Sort by: Most helpful
-
-
Ian Xue 38,861 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.