Enthusiast
Enthusiast

Assistance required running PowerCLI cmdlets from vCO

Hello,

I am trying to run a PowerCLI script from vCenter Orchestrator (5.1.0). So far I have configured the Powershell host and I can run simple powershell scripts, but when it comes to use a cmdlet from PowerCLI I always get an error.  Here are the different things I have tried:

1. Run the "Invoke an external script" workflow: the external script looks like:

Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Connect-VIServer XXXX -NotDefault -User XXXXX -Password XXXXX'
Get-VM -Name XXXXX
Disconnect-VIServer XXXX -Confirm:$false

I get an error message saying that Get-VM fails because there are no Servers connected.

2. I used the "Generate an action for a PowerShell cmdlet"  (using the Get-VM cmdlet) which runs fine and generates a new workflow, but when I run the workflow I get an error "You are not currently connected to any servers. Please connect first using a Connect cmdlet."

3. Then I followed the documentation and used the converter workflow "Convert PSObject to vCO object", here I specify the vCenter credentials  and the following script:

Get-VM -Name XXXXX

I get "'System.OutOfMemoryException' was thrown" error executing Connect-VIServer.

I am kind of lost on what is the correct approach to integrate PowerCLI into vCO.  Basically I want to use a PowerCLI script to customize a guest that has been provisioned through vCO.

Any guidance is appreciated.

Juan.

0 Kudos
4 Replies
VMware Employee
VMware Employee

Did you try invoking the Power shell script outside the vco as normal powershell script?

>> "You are not currently connected to any servers. Please connect first using a Connect cmdlet"

This error points out that Connect-VI server call has failed by some reason. What comes to my mind is if you have some special charackters in the username/password/host that might get encoded.

That's why I suggest :

1. First testing the script outside the vCO

2. If it works try to invoke it as external script from vCO providing the same parameters. But first modify the script to print  the provided parameteres (username/password/hostname) from the script itself to make sure that the correct values are provided to PowerShell script.

Enthusiast
Enthusiast

Thanks for the suggestions Ivo, in fact I had an issue  with my script and as you suggested I was able to run it directly on a shell on the powershell host. The script is very simple and its purpose is just to make sure I can run PowerCLI cmdlets against vCenter:

Param($server,$username,$password)
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue

Write-Output $server
Write-Output $username
Write-Output $password

Connect-VIServer $server -User $username -Password $password
$vm = Get-VM -Name XXX
$vm.Id
Disconnect-VIServer $server -Confirm:$false

When I run the script using the "Invoke an external script" (NOTE: the parameters must be around single quotes) from vCO the workflow hangs and just prints the following message on the logs:

"Invoke command in session 74bf7440-b98e-4271-acc0-a16ea9c57a24"

I have to manually cancel it, but after some retries I started getting an error indicating that the number of WinRM sessions was exceeded (I guess the limit is 5), indicating that every workflow was running in limbo even when I manually canceled it. Anyways, I got rid of that error by restarting the powershell host and decided to run the same script but this time using the "Invoke a PowerShell script" and limiting the PowerCLI commands to just connect to VIServer and to no more. Then, I got the following error:

Connect-VIServer : 1/23/2013 12:55:18 PM    Connect-VIServer        Exception o
f type 'System.OutOfMemoryException' was thrown.   
At line:2 char:17
+ Connect-VIServer <<<<  -Server 'XXXXX' -User 'XXXXXXX' -Pas
sword 'XXXXXXXX'
    + CategoryInfo          : NotSpecified: (:) [Connect-VIServer], ViError
    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_Excep
   tion,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

(Dynamic Script Module name : invokeScript#14)

**Update: After changing the settings on winrm from a command prompt on the Powershell host:

>winrm set winrm/config/winrs @{MaxMemoryPerShellMB="2048"}

I can successfully run the "Invoke a PowerShell script" workflow, but the "Invoke an external script" one still hangs.

Message was edited by: Aristizabal

0 Kudos
Enthusiast
Enthusiast

I got the external script working, I am just posting the fix as it might be of interest to somebody.

As I am using the basic authentication (haven't been able add a Powershell host using Kerberos) I am restricted to use a local Admin account on the powershell host. When running the external script workflow the script is invoked with the call operator (&). I went to the powershell host and opened a powershell cmd as local Administrator and ran the command as it is passed from vCO:

& "c:\mypath\myscript.ps1" -myparameter XXX

I found that the Connect-VIServer cmdlet was prompting to accept the certificate of the server (I haven't configured the certificates yet) therefore when the script is invoked from vCO it just hangs waiting for user input. I also prompted me to accept the VIServer to the default list, I chose to  add it permanently so I am not prompted again.

There should be a more elegant solution like configuring the PowerCLI settings on a user per basis so the script doesn't have to be run manually at least one time to answer the default questions. Anyway, after this procedure vCO can run all the PowerCLI cmdlets without any issues.

0 Kudos
VMware Employee
VMware Employee

Great finding.

Thanks for sharing the solution.

0 Kudos