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?
To get the IIS application pool names using PowerShell, you need to use the IIS PSDrive but for that, we need the IIS PowerShell module WebAdministration or IISAdministration on the server we are running the command. If the WebAdministration module is already installed, use the below command to import the module.
The New-WebApplication cmdlet creates an Internet Information Services (IIS) web application.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With