Each call to set-webconfigurationproperty
will leak a decent amount of memory and will eventually make the current process to hit the MaxMemoryPerShellMb
limit of winrs.
An example of calling set-webconfigurationproperty
+ checking the current process working set in a loop.
All execution is made inside a remote session initiated with new-pssession
and carried out using invoke-command
.
[remoteserver]: PS C:\scripts> winrm get winrm/config/winrs
Winrs
AllowRemoteShellAccess = true
IdleTimeout = 7200000
MaxConcurrentUsers = 10
MaxShellRunTime = 2147483647
MaxProcessesPerShell = 25
MaxMemoryPerShellMB = 1024
MaxShellsPerUser = 30
[remoteserver]: PS C:\scripts>
1..100 | %{
Set-WebConfigurationProperty -PSPath IIS:\ -filter "/system.webserver/rewrite/rewriteMaps/rewriteMap[@name='HostNameToServerMap']/add[@key='www.adomain.com']" -name "value" -value "iis04"
new-object psobject -property @{ WorkingSet = "{0:f2} MB" -f ([System.Diagnostics.Process]::GetCurrentProcess().WorkingSet/1mb); Timestamp = get-date }
}
Timestamp WorkingSet
--------- ----------
2014-10-14 22:10:54 964,45 MB
2014-10-14 22:10:56 981,76 MB
2014-10-14 22:10:57 999,95 MB
2014-10-14 22:10:58 1018,86 MB
Set-WebConfigurationProperty : Not enough storage is available to process this command. (Exception from HRESULT: 0x8007
0008)
At line:2 char:1
+ Set-WebConfigurationProperty -PSPath IIS:\ -filter "/system.webserver/rewrite/re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-WebConfigurationProperty], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.SetConfigu
rationPropertyCommand
2014-10-14 22:10:59 289,46 MB
2014-10-14 22:11:01 216,45 MB
2014-10-14 22:11:02 230,79 MB
2014-10-14 22:11:03 246,11 MB
2014-10-14 22:11:04 263,13 MB
2014-10-14 22:11:05 280,54 MB
2014-10-14 22:11:07 296,83 MB
2014-10-14 22:11:08 313,14 MB
2014-10-14 22:11:09 330,62 MB
2014-10-14 22:11:10 347,47 MB
2014-10-14 22:11:11 365,27 MB
....
The memory consumed by set-webconfigurationproperty
is not being released.
The error occurs when the process hits the limit for a WinRS shell (1024 Mb in my example).
This bug have been around for years and now I have reproduced it on Server 2012 R2, thus IIS 7, 7.5, 8 and 8.5 are all affected.
Is there a better way to (bulk) update the IIS configuration remotely than using set-webconfigurationproperty
of the WebAdministration PowerShell module in a WinRM session?