I have written a powershell script to update username and password of apppool using “webadministration” snapin.
Import-Or-Snapin -Module "Webadministration"
Function Change-AppPoolIdentity {
Param (
$AppPool,
$OldUserName,
$NewUserName,
$Password
)
If (Test-Path $AppPool)
{
LogWrite "Function :Change-AppPoolIdentity"
$MyAppPool = Get-Item $AppPool
If ($($MyAppPool.processModel.userName) -eq $OldUserName) {
$MyAppPool.Stop()
LogWrite "Trying to change App pool user name and password"
$MyAppPool | Set-ItemProperty -Name "processModel.username" -Value $NewUserName
$MyAppPool | Set-ItemProperty -Name "processModel.password" -Value $Password
$MyAppPool.Start()
}
Else {
LogWrite "Apppool $AppPool does not run using $OldUserName"
}
}
Else {
LogWrite "Apppool $AppPool not available "
}
}
After executing the script i was trying to access the site it did not show up. When we did manually set the password it worked. We suspect that password is not updated correctly.
How to ensure that app pool password got changed? After Set-item ,is it possible to add a condition to verify that?
I am relatively new to the IIS powershell provider, but I believe you may need to call set-item in order to save the configuration changes to the application pool.
To test, get the application pool item, print out the processModel password value to see the original value (surprised me when I saw this), then update it, then be sure to call set-item to update IIS.
e.g.