Using VMware PowerCLI - Issue with OO powershell operation that failed to run in parallel (606 Views)
Reply
Visitor
sarfa1
Posts: 2
Registered: ‎10-06-2013
Message 1 of 3 (606 Views)

Using VMware PowerCLI - Issue with OO powershell operation that failed to run in parallel

Hi,

 

Since the OO (9.07) out of box Integration pack for VMware infrastructure is not including all VM configuration options (like VM set annotation/folder search etc..) I decided to try using PowerCLI with Powershell command.

It worked pretty good, and as mention before ,there are a lot of things you can do with powershell and PowerCLI.

 

however , I encountered in a very strange behavior while running this simple powershell script flow:

 

Connect-VIServer -Server 10.10.10.10 -User user-Password  pass

Set-Annotation -Server 10.10.10.10 -Entity "vmName" -CustomAttribute "Case Number" -Value 12345

Disconnect-VIServer -Server 10.10.10.10 -Force -Confirm:$false

 

when running this flow from two different users/PC  in parallel on two different Virtual Machines VM1 & VM2 ,I'm getting this error :" Could not execute powershell command. At line:4 char:15 + Set-Annotation <<<< -Server 10.10.10.10 -Entity "VM1" -CustomAttribute "Customer Email" -Value 12345 ---> VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidState: You have modified the global:DefaultVIServer and global:DefaultVIServers system variables. This is not allowed. Please reset them to $null and reconnect to the vSphere server "

also if I'm not using default variable by adding "-NotDefault" flag to the Connect-VIServer command I'm getting java error : "Connection reset at java.net.SocketInputStream.read..."

meaning somehow the parameters of the first flow is being changed by the 2nd flow run .so the 1st run is crashed in OO Central while the 2nd flow run is completed successfully with no errors.

 

Does anyone have any ideas how I can prevent OO from resetting powershell parameters of two different flow runs?

Does anyone encountered this exception before ?

 

Visitor
sarfa1
Posts: 2
Registered: ‎10-06-2013
Message 2 of 3 (562 Views)

Re: Using VMware PowerCLI - Issue with OO powershell operation that failed to run in parallel

I solved the issue myself .

I moved the script to a background job , this way I can run multiple time same flow without any error or variable resetting.

Occasional Contributor
musami
Posts: 5
Registered: ‎06-29-2012
Message 3 of 3 (471 Views)

Re: Using VMware PowerCLI - Issue with OO powershell operation that failed to run in parallel

Hello, I've same situation and problem, and same error msg:

"..

{Result=1;returnResult=Could not execute powershell command. At line:2 char:104 + if ((Get-PSSnapin | Where-Object { $_.Name -eq "VMware.VimAutomation.Core" }) -eq $null) { Add-PSSnapin <<<< VMware.VimAutomation.Core };returnCode=1;sessionId=de7afff4-e60c-484f-9c41-db3852c63dc4;exception=dotNETWebActions_PowerShell.PowerShellExceptions.CommandException: Could not execute powershell command. At line:2 char:104 + if ((Get-PSSnapin | Where-Object { $_.Name -eq "VMware.VimAutomation.Core" }) -eq $null) { Add-PSSnapin <<<< VMware.VimAutomation.Core } ---> System.ArgumentOutOfRangeException: A requested PowerCLI component was not found on the local system: VMware.VimAutomation.ViCore.Cmdlets ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at VMware.VimAutomation.Sdk.Impl.V1.ComponentManagement.ComponentManager.LoadComponent(String componentName, ComponentInterop& component, ComponentDescriptor& descriptor) --- End of inner exception stack trace --- at VMware.VimAutomation.Sdk.Impl.V1.ComponentManagement.ComponentManager.LoadComponent(String componentName, ComponentInterop& component, ComponentDescriptor& descriptor) at VMware.VimAutomation.Sdk.Impl.V1.ComponentManagement.ComponentManager.LoadComponentAndDependencyList(String componentName) at VMware.VimAutomation.Sdk.Impl.V1.CoreServiceImpl.OnAddSnapin(String componentTypeName) at VMware.VimAutomation.ViCore.Cmdlets.Vim4PSSnapIn.OnInitialize() at VMware.VimAutomation.Sdk.Util10Ps.BaseSnapin.BaseSnapin.get_Cmdlets() at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.MergeCustomPSSnapIn(PSSnapInInfo mshsnapinInfo, CustomPSSnapIn customPSSnapIn) at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadCustomPSSnapIn(PSSnapInInfo mshsnapinInfo) at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo) at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo, PSSnapInException& warning) at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.DoAddPSSnapIn(String name, PSSnapInException& warning) at Microsoft.PowerShell.Commands.AddPSSnapinCommand.AddPSSnapIns(Collection`1 snapInList) at Microsoft.PowerShell.Commands.AddPSSnapinCommand.ProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord() --- End of inner exception stack trace --- at PowerShellV2.PSRunspaceV2.RunCommand[T](PSCommand command) at PowerShellV2.PSRunspaceV2.RunCommand(PSCommand command) at PowerShellV2.PSRunspaceV2.RunScript(String scriptText) at dotNETWebActions_PowerShell.IActions.PowerShellBaseAction.ExecutePowerShell(ActionRequest req, ISession s, IActionRegistry reg);script=#Load VMware Module if ((Get-PSSnapin | Where-Object { $_.Name -eq "VMware.VimAutomation.Core" }) -eq $null) { Add-PSSnapin VMware.VimAutomation.Core } #Enable debug ($debug = 1) $debug = 0 #Disable PowerCLI warning message $WarningPreference = "SilentlyContinue" #Connection parameters $VIServer = "02LOG0043Y.AD02.ENI.INTRANET" $User = "ENI.PRI\ADMAUTREMEXE" $Password = "Milano01" if ($debug -eq 1) { Write-Output "[INFO] ### Cluster List ###" Write-Output "[INFO] Connecting to Virtual Center ${VIServer} ..." } try { #Connect to VCenter $VIConnection = Connect-VIServer $VIServer -User $User -Password $Password if ($debug -eq 1) { if ($VIConnection.IsConnected) { Write-Output "[INFO] Connected to Virtual Center ${VIServer}" } } } catch { $ErrorMessage = $_.Exception.Message $FailedItem = $_.Exception.ItemName Write-Output "Failed to connect to server ${VIServer} as user ${User}" break } $clusterList = Get-Cluster | Select -ExpandProperty Name $output = "" if ($clusterList -eq $null) { if ($debug -eq 1) { Write-Output "[INFO] Cluster list is null" } break } foreach ($cluster in $clusterList) { $output += "${cluster}" $output += ";" } $output = $output -replace(";$", "") Write-Output "$output" #Disconnect from VCenter if ($debug -eq 1) { Write-Output "[INFO] Disconnecting from Virtual Center ${VIServer} ..." } Disconnect-VIServer -Server $VIServer -Force -Confirm:$false if ($debug -eq 1) { if (-not $VIConnection.IsConnected) { Write-Output "[INFO] Disconnected from Virtual Center ${VIServer}" } };}

.."

 

It's like even if im running parallel flow in lanes the PowerCLI thread can be only one..

 

Can you tell me how did you solve this issue?

What you mean with "moved to background job"?

 

Thankx a lot!

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.