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