The following is a test command I am running
$PCCreds = Get-Credential$VM = Get-VM -Name "Test-VM"while ($VM -ne $null){$VM | Invoke-VMScript -GuestCredential $PCCreds -ScriptType Bat -ScriptText 'whoami'Start-Sleep -Seconds 10}
While in this infinite loop I will receive a mixture of successes and failures
ScriptOutput ---------------------------------------------------------------------------------------------------------------------- Test-VM\user | ---------------------------------------------------------------------------------------------------------------------- Invoke-VMScript : 7/9/2012 11:22:12 AM Invoke-VMScript While performing operation 'Connect to host service ' https://vcenter.local/sdk' at port 902' the following error occured: 'Unknown error' At line:15 char:45 + while ($VM -ne $null) {$VM | Invoke-VMScript <<<< -GuestCredential $PCCreds -ScriptType Bat -ScriptText 'whoami'
Start-Sleep -Seconds 60} + CategoryInfo : OperationStopped: (:) [Invoke-VMScript], VimException + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_VixWaitForJob_VixError,VMware.VimAutomation.ViCore.Cmdlets. Commands.InvokeVmScript ScriptOutput ---------------------------------------------------------------------------------------------------------------------- Test-VM\user | ----------------------------------------------------------------------------------------------------------------------
Using that same code with an array of vm objects appears to work without issue. These vms are spread across multiple hosts.
My guess is that this has something to do with sequential connections to same host, reaching a max connection limit, and the connection not being terminated after a successful execution of the cmdlet. Anyone seen this issue before?
Against which vSphere version are you running this ?
And do you use PowerCLI 5.0.1 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Could it be a timing issue on the closing of the socket on port 902 ?
Did you play with the length of the sleep ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I upped it to 60 seconds and the issue remains. I could go higher, but 60+ seconds is an eternity for a timeout. I have yet to find a doc that lists the timeout. Is there a way to force close this connection, without disconnecting from vCenter?
As mentioned earlier, if $vm is an array of vm objects (the array I am testing has 20 vms in it), the cmdlet will run multiple times without issue. But if I change the code to run with a foreach-object:
while ($VM -ne $null) {$VM |% {$_ | Invoke-VMScript -GuestCredential $PCCreds -ScriptType Bat -ScriptText 'whoami'; Start-Sleep -Seconds 10}}
I will receive the same error after the 1st or 2nd vm.
Against which vSphere version are you running this ?
And do you use PowerCLI 5.0.1 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
vSphere version 4.1 Update 2
VMware vSphere PowerCLI 5.0.1 build 581491
I only have vSphere 5 to test against, and the way Invoke-VMScript works has changed in vSphere 5.
Just for info, I could not reproduce the behaviour you are seeing with vSphere 5.
You could have a look in the vmware.log files for one of the VMs where the Invoke-VM fails.
There should be traces of the VIX activity in those logs.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Following your train of thought, I downgraded to VMware-PowerCLI-4.1.1-332441 and it is working without issue.
