pizzim13
Contributor
Contributor

Issue with running invoke-vmscript multiple times on the same VM

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?

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
pizzim13
Contributor
Contributor

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?

Reply
0 Kudos
pizzim13
Contributor
Contributor

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.

Reply
0 Kudos
LucD
Leadership
Leadership

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

View solution in original post

Reply
0 Kudos
pizzim13
Contributor
Contributor

vSphere version 4.1 Update 2

VMware vSphere PowerCLI 5.0.1 build 581491

Reply
0 Kudos
LucD
Leadership
Leadership

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

pizzim13
Contributor
Contributor

Following your train of thought, I downgraded to VMware-PowerCLI-4.1.1-332441 and it is working without issue.

Reply
0 Kudos