Hello
I installed today the Powershell Plugin 1.0.1 and I had for all PowerCLI Scripts system.outofMemoryExceptions.
In the release notes I've read the following: If you run a PowerShell script in a large-scale environment, you might receive a generic system out-of-memory error.
For me it's for all scripts, already a connect-viserver generates MemoryException.
With google 🙂 I've found that with the following command:
winrm set winrm/config/winrs @{MaxMemoryPerShellMB="<MemoryinMB"}
I can change the assigned memory.
I like to know if other users have the same issue, that already very small PowerCLI-scripts generating outofMemoryExceptions and what is the value you configured now?
Thanks for you help.
Hi,
yes we had the same problem in our environment too.
But after setting the parameter you have mentioned everything works fine now.
We also were not able to even connect to the Vcenter before the setting.
Regards
Axel
I had the same issue, but unfortunately changing the memory setting did not fix the issue for me. I needed to run the script in a separate process.
Essentially using "Invoke a PowerShell script" with
After setting MaxMemoryPerShellMB to 2048, everything has worked fine. I recently installed .NET 4.5 and .NET 3.0 on the Win 2k8 R2 box to get PowerShell v3.0 enabled. I need PS v3.0 for the new version of the Add-Computer cmdlet. However, I am now back to getting the 'System.OutOfMemoryException' exception even with no change to MaxMemoryPerShellMB . It fails for "Invoke an external script" and "Convert PSObject to vCO object". I want to avoid re-writing my workflows to allow the invoke-wmimethod to work. Any suggestions?
When iinvoking PowerShell scripts winrm connection is created. MaxMemoryPerShellMB parameter controls the maximum memory that can be used while executing the script on the remote machine.
I would suggest to figure out which PS script is executed when the erro appears and execute directly from PS console. Then check how much memory does it consume.
When running a simple PS1 script that includes a connect-viserver from the powershell console on the remote machine, the memory usage of powershell.exe goes up to about 700MB. It runs without error from the remote machine but fails if run from vCO. If I remove the connect-viserver line, the test script runs fine from vCO. This has something to do with .NET 3.0 and 4.5 which I installed to get Powershell v3.0.
These are my current settings which should be more than fine.
Winrs
AllowRemoteShellAccess = true
IdleTimeout = 7200000
MaxConcurrentUsers = 10
MaxShellRunTime = 2147483647
MaxProcessesPerShell = 25
MaxMemoryPerShellMB = 4096
MaxShellsPerUser = 30
700 MB looks too much for connect-viserver. Is it possible that the script itself returns a lot of data that need to be send as output to vCO.
If it is not private could you attach the PS1 script. I can test it in my environment.
Even this basic script will cause the issue. I tried on another Win2k8 box with .NET 3.0 and 4.5 and it has the same issue.
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Write-Host "Loaded SnapIns:"
Get-PSSnapin | Select Name | ft -AutoSize
Connect-VIServer -Server "vcenter" -User "domain\user" -Password "password"
Write-Host "connected"
Disconnect-VIServer -Confirm:$false
Write-Host "disconnected"
Write-Host "Script is done"
Even with ridiculously high wirm values, I get the error. This is from a 2nd box I am trying to use that is physical with 32 GB RAM.
MaxProcessesPerShell = 500
MaxMemoryPerShellMB = 12288
MaxShellsPerUser = 500
I even tried on a Windows Server 2012 box and have the same issue. I also installed CopSSH on the Win2k8 box, tested and configured that, added it as a Powershell connection. It works but returns null or an error when testing with the sample Powershell workflows. Using a very basic Powershell script, it works fine on a WinRM HTTP session but returns null for the SSH connection. I still have no way of running a PS1 that includes connect-viserver when PowerShell v3.0 is on the box.
I just found out from VMware support that Powershell 3.0 use in vCO is not yet supported and they do not yet have a release date for an updated Powershell plug-in.
From one of the developers "Current version of PowerShell plugin support PowerShell version up to 2.0, PowerShell 3.0 is not supported. Though it is not supported the script executing should work from the plugin. The inventory will not be available when connecting to PowerShell 3.0. "
It could be an issue with Windows Remote Management service itself.
There are couple of threads in Microsoft comunities describing similar issue after upgrading to 3.0.
Invoking PowerShell script with PowerShell Remoting feature could cause outOfMemory exception on some systems.This exception could apper because of a bug in WinRM service causing value set for MaxMemoryPerShellMB to be discarder.
You can check for more details following thread WinRM : quotas setting ignored since KB2506143
I had the same issue - the KB advised above worked for me
I was on Winrm 2.0 and getting the system.OutofMemoryException. Then I ran
winrm set winrm/config/winrs @{MaxMemoryPerShellMB="4096"}
Fixed it for me. By default it was 150MB but setting it to 4GB it ran fine.
Then I upgraded to windows management framework 3.0 and winrm 3.0. IAfter the udpate it stopped working again with the same "system.OutofMemoryException".
However, it still had 4GB of RAM for the MaxMemoryPerShellMB parameter.
Then I uninstalled the Windows Management Framework update 3.0 to go back to winrm 2.0.
After going back to winrm2.0 it set my MaxMemoryPerShellMB back to 150MB. I changed it back to 4GB.
Now it is working again.
Moral of story - works on winrm2.0 only with the larger memory setting. Does not work on winrm 3.0 with any setting.
It appeaars that there is an issue with WMF 3.0 on some windows causing MaxMemoryPerShellMB setting to be discarded
Had some free time to investigate a bit, and here is what I found
The issue is actually is not a vCO PowerShell plugin issue but it is caused by bug in Microsoft WMF 3.0
I was able to reproduce the issue with Windows Server 2008 R2 SP1 and WMF 3.0 are installed.
There is WinRM setting controling the amount of available memory per shell
http://msdn.microsoft.com/en-us/library/ee309367(v=vs.85).aspx
MaxMemoryPerShellMB
The maximum amount of memory allocated per shell, including the shell's child processes. The default is 150 MB.
Note The behavior is unsupported if the MaxMemoryPerShellMB is set to a value that is less than the default.
Unfortunately there is a bug in Microsoft WMF 3.0 that is discarding this setting.
The issue is documented by Microsoft in following kb article : http://support.microsoft.com/kb/2842230
I have retested the plugin against WMF 4.0 and it was functioning properly
Ive also had this problem after updating to powershell 4.
Applying the hotfix from MS resolved the issue.. http://support.microsoft.com/kb/2842230
credits to igaydajiev resolved the issue .:)