help me to rewrite PowerShell script to get the status for IIS app pool on windows 7 and windows 2008 (IIS6).
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)
}
}
If you only need to get the state of an application pool from the current machine, try this:
Import-Module WebAdministration
Get-WebAppPoolState -Name 'DefaultAppPool'