I have an issue - currently I have an IIS server that runs a number of Applicaiton pools that are monitored by running the following bit of Powershell Code:
$applicationPools = get-wmiobject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPoolSetting" | select-object -ExpandProperty Name
$message = ""
$count = 0
foreach ($item in $applicationPools) {
$appPool = Get-WmiObject -Namespace "root\MicrosoftIISv2" -class IIsApplicationPoolSetting -Filter "Name ='$item'"
$applicationPoolStatus = $appPool.AppPoolState
$applicationPoolName = $item -replace "W3SVC/AppPools/", ""
if($applicationPoolStatus -eq "4") {
$message += "- $applicationPoolName is Stopped "
$count++
}
}
if ($count -eq 0) {
echo "0 check_app_pool - All OK"
}
elseif ($message -like "*plesk*") {
echo "2 check_app_pool $message"
}
elseif ($count -le 5) {
echo "1 check_app_pool $message"
}
elseif ($count -gt 5) {
echo "2 check_app_pool $message"
}
The issue currently is that this powershell script needs to be run as Administrator - when run as a non-admin user, it fails to enumerate the WMI classes with Access Denied.
I've tried adding the permissions via WMI Control (in MMC), I've tried setting the WMI Permissions via Powershell using: This Question
I've tried to give Delegated Administrator rights in IIS, but I understand you need to enable Remote Management (which is a security hole)
I'm sure that there is something I've missed with setting WMI Permissions (as this is the first time I've had to do this) but for the life of me, I can't get this working.
Help?