Microsoft has made the goal of their PowerShell APIs a lot easier with Web Application Pools. In this post, we’ll cover how to get started and create your first applications pools.
The “iis application pool advanced settings powershell” is a PowerShell script that allows you to manage IIS Web Application Pools.
Do you need to keep an eye on the app pools on your IIS web server? Here’s how to use PowerShell to build an application pool in IIS.
When you’re in charge of an IIS web server farm with dozens or hundreds of app pools, where do you start? Scripts in PowerShell, of course! You can simply build, alter, and delete app pools at will using the WebAdministrationPowerShell module that is installed as part of IIS plus a little PowerShell remoting.
Let’s look at a few instances of how to do this.
If you’ve never used PowerShell previously to administer your IIS servers, your initial instinct may be to seek for a ComputerName on most of the cmdlets. Regrettably, this isn’t the case.
We’re compelled to utilize PowerShell remoting using the Invoke-Command cmdlet to control IIS servers remotely. It’s not a deal killer, but it does make the code a bit more verbose than it has to be. This isn’t meant to discourage you from using PowerShell to manage remote IIS servers; rather, it’s an FYI.
Related: The Best Way to Run Remote Code with Invoke-Command
I remember being disappointed the first time I attempted this since many of the cmdlets didn’t include the customary ComputerName option.
NOTE: We’ll be writing code to put into a scriptblock in the future. The scriptblock will then be executed on the remote IIS server using Invoke-Command.
Using PowerShell to list IIS Application Pools
We’ll need to import the WebAdministration module first before we can manage web application pools.
PS> Import-Module WebAdministration
This adds all of the IIS cmdlets to the command prompt and establishes the IIS drive. The majority of the app pool setup will be done here. First, let’s investigate whether there are any existing app pools.
PS> Get-ChildItem -Path IIS:AppPools Name State. Applications —– —— ————- GHI Started
Using PowerShell to create new IIS Application Pools
It seems that I already have one named GHI. Perhaps I should make a new one. This is made so much easier by using the IIS drive. Simply use New-Item to create a new item and provide the path.
PS> New-Item -Path IIS:AppPoolsMyAppPool Name State. Applications —– —— ————- MyAppPool Started
Examining and Changing the Properties of the Application Pool
I’ve made a new app pool now. We can then use Get-ItemProperty to verify all of the properties on that app pool, then Choose-Object to select all of the properties it returns. This will return all of the property names and values, allowing you to determine which ones need to be changed using Set-ItemProperty.
IIS:AppPoolsMyAppPool | Get-ItemProperty | select *
Let’s alter a property now that you have an app pool and can view the properties. Perhaps I’d want to utilize a specific.NET runtime version with the app pool. I can use Set-ItemProperty to control app pools using the IIS drive, just as I can manage the file system, registry, certificates, and anything else that has a PowerShell drive.
PS> Set-ItemProperty -Path IIS:AppPoolsMyAppPool -Name managedRuntimeVersion -Value ‘v4.0’
Set-ItemProperty allows you to change virtually all of an app pool’s properties.
Using PowerShell to Remove Application Pools
Finally, we’ve completed our app pool and must now deactivate it. This time, we’ll use the Remove-WebAppPool cmdlet from PowerShell. Simply type in the name and it will be removed!
MyAppPool -Name Remove-WebAppPool
We’ve been running all of our code locally, but what if you need to run it on a remote IIS server? PowerShell remoting comes in handy here. To do this, we’ll simply place all of this code in a scriptblock and use Invoke-Command to run it on the remote server.
‘MyAppPool’ as $appPoolName $scriptBlock = Import-Module WebAdministration New-Item -Path IIS:AppPools $scriptBlock = Import-Module WebAdministration New-Item -Path IIS:AppPools $scriptBlock = Import-Module Set-ItemProperty -Path IIS:AppPools $using:appPoolName Remove-WebAppPool -Name managedRuntimeVersion -Value ‘v4.0’ $using:appPoolName -Name managedRuntimeVersion -Value ‘v4.0’ $using:appPoolName $using:appPoolName $using:appPoolName $using Invoke-Command -ComputerName -ComputerName -ComputerName -ComputerName -ScriptBlock SOMEIISSERVER $scriptBlock
This code would build a new app pool called MyAppPool, set a property, and then delete it, despite the fact that it isn’t really useful. I’m using the $using variable, as you can see. Because the script block’s function will run on a distant computer, PowerShell will need to extend that variable and utilize the real value of $appPoolName that was defined locally on our client PC.
Check out the Technet IIS Administration page if you want to learn more about controlling IIS in general. All of the cmdlets contained in the WebAdministrationmodule are listed there, along with instructions on how to use them.
The “powershell list application pools” is a PowerShell command that will list the names of all the IIS Web Application Pools in your environment.
Frequently Asked Questions
How do I launch app pool in PowerShell?
A: You can search for the Application Pool cmdlet in Windows PowerShell.
How do I restart the application pool in IIS using PowerShell?
A: To restart the application pool on IIS using PowerShell, you can use the following command.
Restart-Service WebApplicationPool -Force
How do I monitor IIS application pool?
A: IIS application pool monitoring is not a thing. Theres no particular tool you can use to monitor the health of an application in Windows, and that includes the Application Pool.
- powershell iis application pool identity
- powershell change application pool identity remotely
- create iis site and application pool powershell
- powershell set app pool identity