This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Problem with Output Statistic

Greetings,

I'm working on a powershell monitor to monitor IIS App pools and restart if necessary, however, I'm getting "no output detected" for some reason. I've done a few of these using similar methods and haven't had any issues, is anyone able to point out any obvious reasons? Here's the script -

$Servers = "VBMDEAPP512"

  #Get Application pool froom remote server

   $AppPools = gwmi -namespace "root\webadministration" -Class applicationpool -ComputerName $Server -Authentication PacketPrivacy -Impersonation Impersonate  | Where-Object {$_.Name -like 'awstats' -or ($_.Name -like 'Repliweb') }

   Foreach ($AppPool in $AppPools){

    #Check Status of App Pool, Status returns 0 to 4 and these refers to above descripted state

    if ($AppPool.GetState().ReturnValue -eq 4){

     Write-Host  "Message.4: $($AppPool.Name) $Server Unknown State"

     Write-Host "Statistic.4: 4"

     }

   

    if ($AppPool.GetState().ReturnValue -eq 3){   

     Write-Host "Message.3: $($AppPool.Name) $Server Stopped State and we're starting it"

     Write-Host "Statistic.3: 3"

     $AppPool.start()

     }

 

 

    if ($AppPool.GetState().ReturnValue -eq 2){     

    Write-Host "Message.2: $($AppPool.Name) $Server Stopping State"

    Write-Host "Statistic.2: 2"

    }  

   

    if($AppPool.GetState().ReturnValue -eq 1){

    Write-Host "Message.1: $($AppPool.Name) on $Server" "is Running"

    Write-Host "Statistic.1: 1"

    }

}

Thanks!