简体   繁体   中英

How to change IIS app pool password on multiple servers at once remotely?

We have a requirement to change our application's IIS app pool password everytime it expires. Currently, we have to manually login to each server and run a snippet of PowerShell code which changes the password.

Here is the code we run on each server on PS:

Import-Module WebAdministration
 $applicationPools = Get-ChildItem IIS:AppPools | where { $_.processModel.userName -eq "Domain\XXXXX12345" }
  
 foreach($pool in $applicationPools)
 {
     $pool.processModel.userName = "Doma\XXXXX12345"
     $pool.processModel.password = "XXXXXXXXXXXXXXXXX"
     $pool | Set-Item
 }
  
 Write-Host "Application pool passwords updated..." -ForegroundColor Magenta 
 Write-Host "" 
 Read-Host -Prompt "Press Enter to exit"

But is there a way we can do the same for a list of servers/VMs at once instead of having to login to each server, open PowerShell or IIS and manually change it on each server?

Any help would be greatly appreciated!

You could try to create an Azure DSC Configuration for this. This way you could provide a new configuration state every time the password expires.

https://docs.microsoft.com/en-us/azure/automation/quickstarts/dsc-configuration

https://writeabout.net/2015/04/15/use-the-dsc-script-resource-to-change-the-application-pool-identity/

could you try this below script:

$computerName = 'MyServerName' $appPoolName = 'DefaultAppPool'

Invoke-Command -ComputerName $computerName -args $appPoolName -ScriptBlock { param($appPoolName) $appPoolName.Stop()

$appPoolName | Set-ItemProperty -Name "processModel.username" -Value "Doma\XXXXX12345" $appPoolName | Set-ItemProperty -Name "processModel.password" -Value "XXXXXXXXXXXXXXXXX"

$targetpool.Start()

}

Write-Host "Application pool passwords updated..."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM