通过Powershell查找未链接到应用程序的IIS应用程序池

时间:2017-12-04 16:08:04

标签: powershell iis

我想编写一个powershell脚本,它将在服务器上找到未链接到应用程序的所有应用程序池,然后删除未使用的应用程序池。

我能想到的一种方法是检索所有应用程序池,检索所有IIS应用程序,然后交叉检查这两个列表。有没有更好的方法呢?

1 个答案:

答案 0 :(得分:1)

对于那些感兴趣的人,这是我写的代码:

$UsedAppPoolList = get-item "IIS:\Sites\*" | foreach { $_.applicationPool; Get-WebApplication -Site $_.Name | foreach { $_.applicationPool } }
$AppPoolExistList = get-item 'IIS:\AppPools\*' | foreach { $_.Name }

foreach ( $AppPool in $AppPoolExistList ){
    if ($UsedAppPoolList -notcontains $AppPool){
        Remove-WebAppPool $AppPool
        write-host "Delete Application Pool $AppPool"
    }
}
相关问题