https://communities.vmware.com/thread/460998
Referencing the above thread.
I've now got Invoke-Command working after enabling a remote session MaxMemory to 2GB. The Session itself uses about 500mb to lead the API and then uses about 163MB to run, after it hits the Get-VM however, it freezes:
Invoke-Command -ComputerName server.domain.com' -Credential $hoAdmin -ArgumentList @($hoadmin, $Vmname) -ScriptBlock {
$cred = $args[0]
$vmname = $args[1]
Write-Host "Passed in $cred, $vmname"
if ( -not (Get-PSSnapIn | where {$_.Name -eq "VMware.VimAutomation.Core"}))
{
Add-PSSnapin -Name "VMware.VimAutomation.Core"
}else{
Disconnect-VIServer -Server * -confirm:$false
}
if ( -not (Get-PSSnapIn | where {$_.Name -eq "VMware.VimAutomation.Core"}))
{
Write-Host "ERROR: Could not get snappin, please confirm you have PowerCLI installed"
break
}
try{
Connect-VIServer -Server @('vcenter1','vcenter2') -Credential $cred -ErrorAction 'Stop'
}catch{
write-host "Could not get connection to one or more vcenter servers"; break
}
$vm = get-vm -name $vmname
}
The above $VM = get-vm -name $vmname now simply hangs and never returns.
Any ideas why this is happening?
Powershell Version 2 and WinRM version 2.
Any comments? This is not answered.
What is in the parameter $VMName ? The name of a specific VM, or a mask that will fit multiple VM.
Is the Connect-VIServer to the 2 vCenters executed ? Successfully ?
When you replace
$vm = get-vm -name $vmname
with
get-vm -name $vmname
do you see any output ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ill give it a shot, but the VM session seems to freeze and not return anything.
Watching on the receiving server i get about 445,000kb for the session on th add-pssnapin and then it returns to about 150, then up to 160ish then just sits there using 0 cpu and no memory variation.