How to use an enum type in powershell when configuring IIS using the powershell snapin How to use an enum type in powershell when configuring IIS using the powershell snapin powershell powershell

How to use an enum type in powershell when configuring IIS using the powershell snapin


It is expecting an integer, even though the underlying property is of type ManagaedPipelineMode. You can do below however:

$AppPool | Set-ItemProperty -Name "managedPipelineMode" -Value ([int] [Microsoft.Web.Administration.ManagedPipelineMode]::Classic)

PS:

Instead of

$AppPool = Get-ChildItem iis:\apppools | where { $_.Name -eq $AppPoolName}

you can do:

$AppPool = Get-Item iis:\apppools\$AppPoolName


Regarding: Add-Type -AssemblyName - this will only work for a canned set of assemblies that PowwerShell knows about. You have to find the assembly in your file system and use the -Path parameter. This worked on my system in a 64-bit PowerShell console:

Add-Type -Path C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll


Instead of using:

$AppPool | Set-ItemProperty -Name "managedPipelineMode" `   -Value [Microsoft.Web.Administration.ManagedPipelineMode]::Integrated

use:

$AppPool | Set-ItemProperty -Name "managedPipelineMode" `   -Value ([Microsoft.Web.Administration.ManagedPipelineMode]::Integrated)

or the even more succinct:

$AppPool | Set-ItemProperty -Name "managedPipelineMode" -Value Integrated

Why? The reason you need brackets in the first answer is because the parameter binder is treating the entire [Microsoft.Web.Administration.ManagedPipelineMode]::Integrated in your attempt as a string, which cannot be cast to that enumerated type. However, Integrated can be to that enum. By wrapping it in brackets, it is evaluated again as an expression and is treated as a full type literal.