Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Set ManagedPipeline for all Application Pools

I've got a command that can list all app pools on a machine:

 Get-WmiObject -namespace "root/MicrosoftIISv2" -class IIsApplicationPool |Select-Object -property @{N="Name";E={$name = $_.Name; $name.Split("/")[2] }} | Format-Table

I want to set the managedpipeline of every app pool on the box. I've tried this:

Get-WmiObject -namespace "root/MicrosoftIISv2" -class IIsApplicationPool |Select-Object -property @{N="Name";E={$name = $_.Name; $name.Split("/")[2] }} | ForEach-Object {cmd /c "c:\windows\system32\inetsvr\appcmd.exe set apppool $name /managedPipleineMode:"Classic"'}

This is giving me a "cannot find the path specified" error. Any ideas how I can this to work?

like image 869
Ken J Avatar asked Oct 05 '12 16:10

Ken J


2 Answers

In order to set the Managed Pipeline mode (or any property of the AppPool), you need to use Set-ItemProperty. But it gets more fun than that:

  1. Set-ItemProperty takes a Path as its input. Get-ChildItem will return you a collection of ConfigurationElement objects, not Path strings.
  2. ManagedPipelineMode is internally stored as an integer, so you have to know the correct "magic" number to pass in. Fortunately, that is documented here, in the "Remarks" section.

This did the trick for me:

Import-Module WebAdministration
Get-ChildItem IIS:\AppPools |
    Select-Object -ExpandProperty PSPath |
    ForEach-Object { Set-ItemProperty $_ ManagedPipelineMode 1 }
like image 156
JamesQMurphy Avatar answered Sep 30 '22 07:09

JamesQMurphy


following the documentation :

$iisAppPoolName = "MyPool"
$appPool = New-WebAppPool -Name $iisAppPoolName  
$appPool.managedPipelineMode = "Classic"
$appPool |Set-Item

I tested, IIS 8.0, Windows server 2012, and it works.

like image 32
XtianGIS Avatar answered Sep 30 '22 06:09

XtianGIS