Power shell 脚本以获取应用程序池的状态

Power shell script to get states for app pool

帮助我重写 PowerShell 脚本以获取 windows 7 和 windows 2008 (IIS6) 上 IIS 应用程序池的状态。

function Get-AppPool {

    [CmdletBinding()]

    param
    (

    [string[]]$Server,
    [String]$Pool

    )

#region loadAssembly 

[Reflection.Assembly]::LoadWithPartialName('Microsoft.Web.Administration')

#endregion loadAssembly

foreach ($s in $server)

{

$sm = [Microsoft.Web.Administration.ServerManager]::OpenRemote($s)

$apppools = $sm.ApplicationPools["$pool"]

$status = $apppools.state


        $info = @{
        'Pool Name'=$pool;
        'Status'=$status;
        'Server'=$S;
        }

        Write-Output (New-Object –Typename PSObject –Prop $info)

        }

    }

如果您只需要从当前机器获取应用程序池的状态,试试这个:

Import-Module WebAdministration
Get-WebAppPoolState -Name 'DefaultAppPool'