I am making multiple pssessions that connect to my local host as to query multiple vCenter as jobs then using invoke-command as below
foreach ($SrvSession in $vCenterSessions)
{
Invoke-Command -session $SrvSession -ScriptBlock { `
$SnapInfo = Get-VM | Get-Snapshot | Select-Object VM, Name, Description, Created, Powerstate, @{N="VI Server";E={$DefaultVIServer.Name}}
$SnapInfo
} -AsJob -HideComputerName
}
It seems that running get-vm (even by itself) via invoke-command throws an error that fails the script
WARNING: 'Description' property is obsolete. Use 'Notes' instead.
WARNING: 'HardDisks' property is obsolete. Use 'Get-HardDisk' cmdlet instead.
WARNING: 'NetworkAdapters' property is obsolete. Use 'Get-NetworkAdapter' cmdlet instead.
WARNING: 'UsbDevices' property is obsolete. Use 'Get-UsbDevice' cmdlet instead.
WARNING: 'CDDrives' property is obsolete. Use 'Get-CDDrive' cmdlet instead.
WARNING: 'FloppyDrives' property is obsolete. Use 'Get-FloppyDrive' cmdlet instead.
WARNING: 'Host' property is obsolete. Use 'VMHost' instead.
WARNING: 'HostId' property is obsolete. Use 'VMHostId' instead.
Processing data for a remote command failed with the following error message:The WSMan provider host process did not return a proper response. A provider in the host
process may have behaved improperly. For more information, see the about_Remote_Troubleshooting Help topic.
Using this same process with get-view works without issue. Running get-vm outside of the pssession also works. Any ideas?
Can you provide the info you are using to fill in $vCenterSessions variable? That error looks like it's having issues w/ powershell remoting.
#Create a local session for each vCenter server
$vCenterSessions = New-Object System.Collections.ArrayList
foreach ($vCenter in $Config.AppSettings.vCenters.HostName)
{
$vCenterSessions.add((New-PSSession -ComputerName localhost -Name $vCenter)) | out-null
}
$Config.AppSettings.vCenters.HostName is an array of vCenter servers gathered from an XML file. I have many more working examples of this using get-view. See below:
###Connect to each session to get VM info
foreach ($SrvSession in $vCenterSessions)
{
Invoke-Command -session $SrvSession -ScriptBlock { `
$VMInfo = @()
$VMInfo = Get-View -ViewType VirtualMachine -Property Guest.toolsVersionStatus, Config.Template, Runtime.PowerState, Config.guestfullname, Config.Version |
Select-Object @{N="Tools Status";E={$_.Guest.toolsVersionStatus}}, @{N="Template";E={$_.Config.Template}}, `
@{N="Power State";E={$_.Runtime.PowerState}}, @{N="Guest OS";E={$_.Config.guestfullname}}, `
@{N="HW Version";E={$_.Config.Version}}, @{N="VI Server";E={$DefaultVIServer.Name}}, `
@{N="VM";E={$_.Name}}
$VMInfo
} -AsJob -HideComputerName
}
Get-Job | Wait-Job
$VMInfo = @()
$VMInfo += Get-Job | Receive-Job