The WebAdministration module has a Function called IIS:. It essentially acts like a drive letter or an uri protocol. Its really convenient and makes accessing appPool, site information, and ssl bindings easy.
I recently noticed two problems with assigning values through the IIS: protocol or the objects which is works with:
StartMode Can’t Be Set Directly
For some reason, using Set-ItemProperty to set the startMode value directly throws an error. But, if you retrieve the appPool into a variable and set the value using an = operator, everything works fine.
# https://connect.microsoft.com/PowerShell/feedbackdetail/view/1023778/webadministration-apppool-startmode-cant-be-set-directly ipmo webadministration New-WebAppPool "delete.me" Set-ItemProperty IIS:\AppPools\delete.me startMode "AlwaysRunning" # throws an error $a = Get-Item IIS:\AppPools\delete.me $a.startMode = "AlwaysRunning" Set-Item IIS:\AppPools\delete.me $a # works
Here is the error that gets thrown:
Set-ItemProperty : AlwaysRunning is not a valid value for Int32. At C:\Issue-PowershellThrowsErrorOnAppPoolStartMode.ps1:6 char:1 + Set-ItemProperty IIS:\AppPools\delete.me startMode "AlwaysRunning" # throws an e ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Set-ItemProperty], Exception + FullyQualifiedErrorId : System.Exception,Microsoft.PowerShell.Commands.SetItemPropertyCommand
CPU’s resetLimit Can’t Directly Use New-TimeSpan’s Result
I think the example can show the problem better than I can describe it:
# https://connect.microsoft.com/PowerShell/feedbackdetail/view/1023785/webadministration-apppools-cpu-limit-interval-resetlimit-cant-be-set-directly ipmo webadministration New-WebAppPool "delete.me" $a = Get-ItemProperty IIS:\AppPools\delete.me cpu $a.resetInterval = New-TimeSpan -Minutes 4 # this will throw an error Set-ItemProperty IIS:\AppPools\delete.me cpu $a $a = Get-ItemProperty IIS:\AppPools\delete.me cpu $k = New-TimeSpan -Minutes 4 # this will work $a.resetInterval = $k Set-ItemProperty IIS:\AppPools\delete.me cpu $a
Here is the error that gets thrown:
Set-ItemProperty : Specified cast is not valid. At C:\Issue-PowershellThrowsErrorOnCpuLimitReset.ps1:8 char:1 + Set-ItemProperty IIS:\AppPools\delete.me cpu $a + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Set-ItemProperty], InvalidCastException + FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.SetItemPropertyCommand
The links on each section correspond with bug reports for the issues, so hopefully they will get looked into.
0 comments:
Post a Comment