Partager via


How to create daily reports with System Center Operations Manager 2012 and PowerShell - Part 5

This series of blogs aims to show administrator how to create daily reports summarising the health of Operations Manager using PowerShell. This should reduce the overheads required for daily health reviews of their system environments

In this fifth and final entry in the blog series explains how PowerShell can be used to audit your Operations Manager environment for analysis and then output onto an HTML page. 

Auditing changes to your environment is essential to ensuring Operations Manager is being managed correctly and this blog is certainly not meant to be a replacement for documenting changes in your environment. In the event of a failure or an issue occurring a good audit log is always essential to diagnose. I recommend ensuring you have read the following blog posts and ensuring you have a policy in place for your disaster recovery process and Management Pack Lifecycle as a starting point.

 

Management Pack Lifecycle:

https://technet.microsoft.com/en-us/library/hh212732.aspx

Disaster Recovery in System Center 2012 - Operations Manager:

https://technet.microsoft.com/en-us/library/hh531578.aspx

 

The following script helps review key changes in your environment, allowing effort to be focused on key problem areas to ensure your resources can be assigned appropriately.

 

#Outputs header and formatting for Auditing

$ReportOutput += "</br>"

$ReportOutput += "<hr size=4 width=50% align=left>"

$ReportOutput += "<h6>Auditing</h6>"

 

#Outputs header and formatting for Management Packs added in the last 24 Hours

$ReportOutput += "<h2>Management Packs added in the last 24 Hours</h2>"

 

  #Checks current date -1 day looking for any management packs installed with a greater Time Created

$olddate = (Get-Date).AddDays(-1) 

$Count = Get-SCOMManagementpack | Where-Object { $_.TimeCreated -gt $olddate}

if($Count.Count -gt 0) {

                    $ReportOutput += Get-SCOMManagementpack | Where-Object { $_.TimeCreated -gt $olddate} | select Name,TimeCreated | ConvertTo-HTML

} else {

$ReportOutput += "<p><h4>No Management Packs have been Added in the last 24 Hours.</h4></p>"   

}

 

#Outputs header and formatting for Manually Installed Agents

$ReportOutput += "<br></br>"

$ReportOutput += "<hr size=4 width=50% align=left>"

$ReportOutput += "<h2>Manually Installed Agents</h2>"

 

#Gets all Agents where ManuallyInstalled value is true and outputs

$Count = get-SCOMagent | where {$_.ManuallyInstalled -eq $True}

if($Count.Count -gt 0) {

                      $ReportOutput+= get-SCOMagent | where {$_.ManuallyInstalled -eq $True} | select Name | ConvertTo-HTML

} else {

$ReportOutput += "<p><h4>No Agents are Manually Installed.</h4></p>"    

}

 

#Outputs header and formatting for Computers in Maintenance Mode

$ReportOutput += "<br></br>"

$ReportOutput += "<hr size=4 width=50% align=left>"

$ReportOutput += "<h2>Computers in Maintenance Mode</h2>"

 

#Gets all Windows Computers and checks InMaintenanceMode value then loops through each computer in Maintenance mode to check values

$ReportOutput +=
"<h2>Computers in Maintenance Mode</h2>"

 

$mc = get-scomClass
-name Microsoft.Windows.Computer

$mo = Get-SCOMClassInstance  $mc | Where {$_.InMaintenanceMode -eq 'True'}

$mv = $mo | measure

 

if($mv.Count -gt
0)

{

    foreach ($Mo in $Mo)

                        $ReportOutput += "<h3>$mo</h3>"

                        $ReportOutput += $mo | get-scommaintenancemode | Select StartTime,ScheduledEndTime,EndTime,Reason,Comments,User | ConvertTo-HTML

}

 

} else {

$ReportOutput +="<h4>No Computers are in Maintenance Mode</h4>"

}

 

 

Now run using the command from the previous blog to start the script, replacing parameters as required, as illustrated in this example:

PowerShell.exe Daily-Report.ps1 MSServerName c:\scripts Daily-Report.htm

 

This will produce a report similar to the below:

 

 

 

 

Daily-Report.ps1

Comments

  • Anonymous
    January 01, 2003
    We have implemented this script, with a few tuning to suit our environment. Great tool for Ops Admin team. Thanks

  • Anonymous
    February 07, 2014
    Hi Everyone, Recently while working for a customer, I got a query around generating a real time report