29
votes

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?

1

1 Answers

48
votes

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