Tuesday, October 2, 2012

IIS: Update Application Pool user passwords

Hi guys,
I wanted to share a short powershell script for updating Application Pool user's passwords.

You have Application Pools which are running with a user identity (Custom Account). When the user's password is changed, you have to update all Application Pools and set the new password.
For instance, if you're using your credentials for the Application Pools and you have a policy to change your password timely based, you have to go every time and change your password in the Application Pools users, too.

Why would I use my identity for an application pool? One reason I do it is so that I can easily start a SQL Profiler at any time, change the connection strings to use "Integrated Security" and capture all requests to the SQL server and filter them by my identity name.

Pretty straight-forward Powershell script - Get All Application pools on the IIS, which are with the identity you want. Iterate and update their passwords.

Import-Module WebAdministration
$applicationPools = Get-ChildItem IIS:\AppPools | where { $_.processModel.userName -eq "domain\username" }

foreach($pool in $applicationPools)
    $pool.processModel.userName = "domain\username"
    $pool.processModel.password = "newpassword"
    $pool.processModel.identityType = 3
    $pool | Set-Item

Happy scripting!