Okay, I have found a solution, or rather a workaround.
Instead of using IIS Webadministration PS module cmdlets, I have found alternative ways to get IIS App Pool and IIS Web Site status data.
This is how my PowerShell part looks like in each:
App Pool Availability Monitor
# Begin MAIN script section
#=================================================================================
$counters = Get-Counter -Counter "\APP_POOL_WAS(*)\Current Application Pool State"
$strCondition = $counters.countersamples | where InstanceName -ne "_total"
foreach ($strCond in $strCondition) {
$bag = $momapi.CreatePropertyBag()
$PoolID = $strCond.InstanceName
$AppPoolStatus = $strCond.RawValue
$bag.AddValue('PoolID',$PoolID)
#Check the value of $strCond
IF ($AppPoolStatus -eq '3') {
$momapi.LogScriptEvent($ScriptName,$EventID,0,'Good Condition Found')
$bag.AddValue('Result','Running')
} else {
$momapi.LogScriptEvent($ScriptName,$EventID,0,'Bad Condition Found')
$bag.AddValue('Result','NotRunning')
}
$bag
}
# End of script section
Web Site Availability Monitor
# Begin MAIN script section
#=================================================================================
$strCondition = Invoke-Expression "$env:SystemRoot\system32\inetsrv\AppCmd.exe list site"
foreach ($strCond in $strCondition) {
$bag = $momapi.CreatePropertyBag()
$DisplayName = $strCond.Split('"')[1]
$WebSiteStatus = $strCond.Split(':')[-1]
$bag.AddValue('DisplayName',$DisplayName)
#Check the value of $strCond
IF ($WebSiteStatus -eq 'Started)') { # Started) is okay because that's the result of splitting the string
$momapi.LogScriptEvent($ScriptName,$EventID,0,'Good Condition Found')
$bag.AddValue('Result','Running')
} else {
$momapi.LogScriptEvent($ScriptName,$EventID,0,'Bad Condition Found')
$bag.AddValue('Result','NotRunning')
}
$bag
}
# End of script section
I still don't understand why those two cmdlets are causing so much overhead, hopefully I will find out one day.