1

I´m working with SCOM (SystemCenterOperationsManager) and wrote a little script for an scheduled task.

It should collect all NEW ( ResolutionState = 0 ) Alerts and filter them with my Wildcard rule.

It will Change the resolution state for all collected alerts to an specific Resolution state.

My Problem:

To get an Report for all the Chosen alerts I want to generate an "Out-file" Where should I place it ?

Here is my code:

if ($LastHourAlerts)
{
   foreach($Alert in $LastHourAlerts)
   {      
   $newState = $null

   switch -wildcard ($Alert.Name) 
      {
      "Operations Manager failed to start a process" { $newState = 255 } 
      "Operations Manager failed to check the state of a service" { $newState = 255 }
      "Operations Manager failed to run a WMI query" { $newstate =255 }
      "Interface Utilization Alert" { $newState = 15 }
      "Veeam VMware: Datastore Provisioning Analysis" { $newState = 17 }
      "Veeam VMware Collector: VMware connection data processing errors" { $newState = 17 }
      "Veeam VMware Collector: VMware connection is unavailable" { $newState = 17 }
      "Veeam VMware: Virtual Machine Memory Usage Analysis" { $newState = 17 }
      "Veeam VMware: Virtual Machine CPU Usage Analysis" { $newState = 17 }
      "Veeam VMware: Virtual Machine Memory Ballooning and Swapping Analysis" { $newState = 17 }
      "Veeam VMware: Virtual Machine Storage Latency Analysis" { $newState = 17 }
      "Veeam VMware: Virtual Machine Consolidation Needed status Alarm" { $newState = 17 }
      "Veeam VMware: Maintenance Mode Tracker" { $newState = 17 }
      "Veeam VMware: vSphere Host Storage Commands Failed Analysis" { $newState = 17 }
      "Veeam VMware: vSphere Host Network Packet Loss Analysis" { $newState = 17 }
      "Veeam VMware: vSphere Host Memory Swapping Analysis" { $newState = 17 }
      "Veeam VMware: vSphere Host Memory Usage Analysis" { $newState = 17 }
      "Veeam VMware: vSphere Host Kernel Latency Analysis" { $newState = 17 }
      "Veeam VMware: vSphere Cluster Memory Overcommit Analysis" { $newState = 17 }
      "Veeam VMware: VM customization failed" { $newState = 17 }

      }


      if($newState -ne $null)
         {
         $Alert.ResolutionState = $newState
         $Alert.Update(“Resolution State changed automatically by Automation”)              
         }
     }    
}

I tríed something like this in the end of the if Loop:

$Alert.Name | Out-File ("$path\" + "Report.csv") -Append

Although it takes the name, but writes only the name of the first alarm object in the number of all processed alarms. For example:

5 different Alerts:

Operations Manager failed to start a process
Interface Utilization Alert
Veeam VMware: VM customization failed
Veeam VMware: Virtual Machine CPU Usage Analysis
Veeam VMware Collector: VMware connection is unavailable

and that´s in the .csv:

Operations Manager failed to start a process
Operations Manager failed to start a process
Operations Manager failed to start a process
Operations Manager failed to start a process
Operations Manager failed to start a process

Is there a better way to get a data output? Also, I would not only like to have the $Alert.Name but $Alert.Name, $Alert.TimeRaised, $ResolutionState.

  • Do these actually have a resolution state 0? Check with `$Alert | Format-Table Name, ResolutionState -AutoSize`. – Ansgar Wiechers Mar 23 '16 at 11:47
  • No, they have received their proper predetermined value like: ` switch -wildcard ($Alert.Name) { "Operations Manager failed to start a process" { $newState = 255 }` – T. Schröder Apr 04 '16 at 09:03

1 Answers1

0

Put something like this at the end of your loop:

if ($Alert.ResolutionState -eq 0) {
  $Alert.Name | Out-File 'C:\path\to\your.txt' -Append
}
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328