VMware Cloud Community
Craig_Baltzer
Expert
Expert

Freeze when running PowerCLI cmdlets via invoke-command

I'm trying to run a bit of PowerCLI on a remote server using invoke-command. I'm hitting a wall where the execution "hangs" after the connect-viserver cmdlet executes.
I've increased the memory available for remote processes on that server to 2GB (i.e. I've run set-item wsman:localhost\Shell\MaxMemoryPerShellMB 2048 on the remote server and restarted).

Remote execution works fine as I can do

invoke-command -ComputerName server.bob.com -Scriptblock { get-help}

this returns the output from "get-help" as expected

Likewise I can load the PowerCLI snap-in and connect to a vSphere host

invoke-command -ComputerName server.bob.com -Scriptblock { add-pssnapin VMware.VimAutomation.Core; connect-viserver vsserver.bob.com -User root -Password pwd; get-help}

this returns the output from connect-viserver showing that I connected to the host, then the "get-help" output follows as expected

The burn comes when I try to run another VMware cmdlet

invoke-command -ComputerName server.bob.com -Scriptblock { add-pssnapin VMware.VimAutomation.Core; connect-viserver vsserver.bob.com -User root -Password pwd; get-vmhost}

this returns the output from connect-viserver and then just hangs (I have to close the PowerShell instance to get control back). The cmdlet doesn't matter (i.e. get-vm will also hang)

The underlying OS is Windows 2008 R2 and I've tried both 5.0 (build 435427) as well as 5.5 PowerCLI (build 1295336) with the same results. Any thoughts?

27 Replies
georgep
Contributor
Contributor

I too also have this problem. Has there been any resolution to this? I was trying to run a script on a remote computer that doesn't have PowerCLI installed and so thought that this method would be a work around and now I have the same issues as mentioned above. I just wish that PowerCLI cmdlets could be added easily using "Import-Module" ....something that so be worked on for future releases.

0 Kudos
LucD
Leadership
Leadership

Do you see the same when you pipe the objects from Get-VMHost or Get-VM to an Out-String or a Select-Object cmdlet ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

georgep
Contributor
Contributor

Hi LucD,

Ok as mentioned using Select-Object works Smiley Happy. I had  missed that off.

So this works

Invoke-Command -ComputerName SRV -Scriptblock {add-pssnapin VMware.VimAutomation.Core; connect-viserver VC1; Get-vm | select-object Name}

Invoke-Command -ComputerName SRV -Scriptblock {add-pssnapin VMware.VimAutomation.Core; connect-viserver VC1; Get-Host | select-object Name}

Without | Select-Object they don't return any results. I've yet to install PowerCLI 5.8 but will shortly.

Thanks to all for posting on this issue and a simple work around.

georgep
Contributor
Contributor

Noticed that Open-VMConsoleWindow' doesn't work however.

"The term 'Open-VMConsoleWindow' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the

path is correct and try again."

0 Kudos
LucD
Leadership
Leadership

Which PowerCLI version are you using ?

Do a

Get-PowerCLIVersion


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
georgep
Contributor
Contributor

you were right to ask what version the machine had.....5.1 .....I have now upgraded to 5.8 release 1.

However when I ran this command

Invoke-Command -ComputerName SRV -Scriptblock {add-pssnapin VMware.VimAutomation.Core; connect-viserver VC1; Open-VMConsoleWindow  'MyVM'}

It connect's to the VC and then after some time completes but without opening the browser. Doing it as normal i.e  Open-VMConsoleWindow 'MyVM'

works.

Has anyone tried this? or is there any other way to open a VM console window using Invoke-Command?

0 Kudos
georgep
Contributor
Contributor

Also it appears your can't use a String value

$VC = "VirtualCenter"

Invoke-Command -ComputerName SRV -Scriptblock {add-pssnapin VMware.VimAutomation.Core; connect-viserver $VC; Get-vm | select-object Name}

Error:

Cannot validate argument on parameter 'Server'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.

+ CategoryInfo     : InvalidData: (:) [Connect-VIServer], ParameterBindingValidationException

+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

+ PSComputerName   :  MyComputer

0 Kudos
LucD
Leadership
Leadership

Passing parameters via Invoke-Command to a script block is done with the ArgumentList parameter

See for example #PSTip Passing local variables to a remote session in PowerShell 3.0


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference