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

查找未通过Powershell链接到应用程序的IIS应用程序池,powershell,iis,Powershell,Iis,我想编写一个powershell脚本,该脚本将查找服务器上所有未链接到应用程序的应用程序池,然后删除未使用的应用程序池 我可以想到的一种方法是检索所有应用程序池,检索所有IIS应用程序,然后交叉检查这两个列表。有更好的方法吗?对于那些感兴趣的人,以下是我编写的代码: $UsedAppPoolList = get-item "IIS:\Sites\*" | foreach { $_.applicationPool; Get-WebApplication -Site $_.Name | foreac

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


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

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

$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"
    }
}

这似乎是唯一的办法。