Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why/How is ManagedPipelineMode a different type when Getting vs Setting?

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:

  1. What is this strange behaviour that allows a property to be a string when read, but int when set? Is this the case for all enums?
  2. Is there any way to read/write this property using the same type, so I can write code that is able to read the value, check if it's what we want, and if not, update it?
like image 407
Danny Tuppeny Avatar asked Oct 06 '22 05:10

Danny Tuppeny


2 Answers

Use the following values: 0 = Integrated; 1 = Classic

Set-ItemProperty "IIS:\AppPools\MyAppPool" "managedPipelineMode" "1"
like image 93
Umar Avatar answered Oct 23 '22 11:10

Umar


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.

like image 1
Eris Avatar answered Oct 23 '22 10:10

Eris