ZeroBugBounce
ZeroBugBounce

Reputation: 3670

How can you change an IIS Site's App Pool with the Powershell Web Admin Commandlets

The following code demonstrates what I thought might work, but it doesn't change the app pool - it remains set at its current value (even though the $site object does update):

import-module WebAdministration

$site = get-item "IIS:\Sites\Project"
$site.ApplicationPool = "ProjectAppPool"
$site | set-item

If you create the site with New-WebSite specifying the -ApplicationPool parameter, it creates as expected. What Powershell IIS web command must I use to change an existing site's app pool to something different?

Upvotes: 35

Views: 34469

Answers (2)

toscanelli
toscanelli

Reputation: 1241

In my case this worked. Important Start and Stop commit delay:

Start-IISCommitDelay
$ThisSite = Get-IISSite "whatever"
$ThisSite.Applications["/"].ApplicationPoolName = $poolName
Stop-IISCommitDelay

Upvotes: -1

Keith Hill
Keith Hill

Reputation: 201952

ApplicationPool is a property on the web site in the IIS: drive. Set it like so:

#site level
Set-ItemProperty 'IIS:\Sites\Default Web Site' applicationPool ProjectAppPool

#app level
Set-ItemProperty 'IIS:\Sites\Default Web Site\AppName' applicationPool ProjectAppPool

If you have the PowerShell Community Extensions installed, you can use the Show-Tree command to explore these drives e.g.:

Show-Tree IIS:\Sites -ShowProperty -Depth 1

Upvotes: 54

Related Questions