While trying to write some scripts to manage our IIS sites, I came across some strange behaviour with the ManagedPipelineMode in IIS. My code is fairly generic, and uses Get-ItemProperty to read the old value, then Set-ItemProperty to update it if it's not the value we want.
However, if I run this:
Get-ItemProperty "IIS:\AppPools\MyAppPool" "managedPipelineMode"
I get back the string Classic
. However, if I run this:
Set-ItemProperty "IIS:\AppPools\MyAppPool" "managedPipelineMode" "Classic"
I get back the error Classic is not a valid value for Int32
.
So, I know I can set the value using ([int][Microsoft.Web.Administration.ManagedPipelineMode]::Classic)
, but I don't understand why the type seems to be different when using Get-ItemProperty
vs Set-ItemProperty
, or how I can query this in a way that behaves consistently.
Note: I don't really want to put a special case in for ManagedPipelineMode, as every other property seems to behave as expected. So, two questions:
string
when read, but int
when set? Is this the case for all enums?Use the following values: 0 = Integrated; 1 = Classic
Set-ItemProperty "IIS:\AppPools\MyAppPool" "managedPipelineMode" "1"
Try using
Set-ItemProperty -Path:'IIS\AppPools\MyAppPool' -Name:'managedPipelineMode' -Value:Classic
Note the lack of quotation marks on Classic
Notes: I prefer to call argument names specifically so there is no confusion later, and if they update/change the command, wierd stuff doesn't happen
I also use the colon binding operator. This makes it absolutely clear that the value belongs to an argument of that name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With