I am pulling my hair here because I just can't get it to work, and I can't figure out how to solve this problem. I am running Powershell 2.0. Here is my script:
$computer_names = "server1,server2" Write-Output "Invoke-Command -ComputerName $computer_names -ScriptBlock { Get-WmiObject -Class Win32_LogicalDisk | sort deviceid | Format-Table -AutoSize deviceid, freespace }" Invoke-Command -ComputerName $computer_names -ScriptBlock { Get-WmiObject -Class Win32_LogicalDisk | sort deviceid | Format-Table -AutoSize deviceid, freespace }
The last command gives an error:
Invoke-Command : One or more computer names is not valid. If you are trying to pass a Uri, use the -ConnectionUri parameter or pass Uri objects instead of strings.
But when I copy the output of the Write-Output command to the shell and run it, it works fine. How can I apply a string variable to what Invoke-Command accepts? Thanks in advance!
source share