MidWest Management Summit 2014 Administrative Uses of PowerShell in SCOM 2012

November 12, 2014 Leave a comment

Here is a dump of the one liners and examples from my Administrative Uses of PowerShell in SCOM 2012.

 

# NEED TO KNOW for writing effective PowerShell criteria based queries to the opsmgr db.
# Severity : Critical = 2,  Warning = 1, Information = 0
# Priority : High = 2, Medium = 1, Low = 0
# ResolutionState: Closed = 255, New = 0
# IsMonitorAlert: True = 1, False = 0

#Importing the SCOM PowerShell module
Import-module OperationsManager
#Connect to localhost when running on the management server
$connect = New-SCOMManagementGroupConnection –ComputerName localhost

# Or enable the two lines below and of course enter the FQDN of the management server in the first line.
#$MS = "enter.fqdn.name.here"
#$connect = New-SCOMManagementGroupConnection –ComputerName $MS

#Get New Critical Alerts Counts
(Get-SCOMAlert -ResolutionState 0 -Severity 2).count
#Get A count of all Critical alerts both open and closed
(Get-SCOMAlert -ResolutionState 0,255 -Severity 2).count
#Get New Warning Alerts Counts
(Get-SCOMAlert -ResolutionState 0 -Severity 1).count
#Get New Informational Alerts Counts
(Get-SCOMAlert -ResolutionState 0 -Severity 0).count

#get a count of rule based alerts
(Get-SCOMAlert -criteria "IsMonitorAlert=0").count
#Get a count of monitor based alerts
(Get-SCOMAlert -criteria "IsMonitorAlert=1").count

#WILL THIS WORK? NO, once IsMonitorAlert is added as a part of the criteria, have to use ""
#(Get-SCOMAlert -resolutionstate 0 -severity 2 -Criteria "IsMonitorAlert = 0").count
#the following line will work
(Get-SCOMAlert -Criteria "ResolutionState = 0 AND Severity = 1 AND IsMonitorAlert = 0").count
#the order of the critera is not that important unless your data set is large, in that case use the big filter first
(Get-SCOMAlert -Criteria "IsMonitorAlert = 0 and ResolutionState = 0 AND Severity = 1").count

#Get New Error Alerts, sort by Name
Get-SCOMAlert -ResolutionState 0 -Severity 2 | sort Name
#Get New Warning Alerts, sort by name
Get-SCOMAlert -ResolutionState 0 -Severity 1 | sort Name
#Get New Informational Alerts, sort by name
Get-SCOMAlert -ResolutionState 0 -Severity 0 | sort Name

# Get a list of open ERROR alerts created by a monitor
Get-SCOMAlert -Criteria "ResolutionState = 0 AND Severity = 2 AND IsMonitorAlert = 1"

# get a LIST of open alerts created by a monitor
Get-SCOMAlert -Criteria "ResolutionState = 0 AND IsMonitorAlert = 1"
# get a COUNT of open alerts created by a monitor
(Get-SCOMAlert -Criteria "ResolutionState = 0 AND IsMonitorAlert = 1").count

# get a LIST of open alerts created by a rule
Get-SCOMAlert -Criteria "ResolutionState = 0 AND IsMonitorAlert = 0"
# get a COUNT of open alerts created by a rule
(Get-SCOMAlert -Criteria "ResolutionState = 0 AND IsMonitorAlert = 0").Count

# get list of closed alerts created by a monitor
Get-SCOMAlert -Criteria "ResolutionState = 255 AND IsMonitorAlert = 1"

# get list of closed alerts created by a rule
Get-SCOMAlert -Criteria "ResolutionState = 255 AND IsMonitorAlert = 0"
# get a list of open alerts that are warning alerts
Get-SCOMAlert -Criteria "ResolutionState = 0 AND Severity = 1"
# open critical alerts
Get-SCOMAlert -Criteria "ResolutionState = 0 AND Severity = 2"
# Open Critical and Warning alerts
Get-SCOMAlert -ResolutionState 0 -Severity 2,1

# Becasue you would never want to close an alert generated by a monitor, with out resetting #the health of the alerts monitor. There will not be a one liner that will close alerts generated #by a monitor. There will be a script that will do that available soon.

# Get New Alerts generated by a rule, and close the alerts.
Get-SCOMAlert -Criteria "ResolutionState = 0 AND IsMonitorAlert = 0" | Resolve-SCOMAlert -Comment ‘Alerts Closed by Chuck Norris’

#SCOM 2012 backup all MPS
Get-SCManagementPack | Export-SCManagementPack -path c:\MPBackup

#Get Agents that are not healthy
Get-SCOMAgent | where {$_.HealthState -ne “Success”}

#how to enable agent proxy
Get-SCOMAgent |where {$_.ProxyingEnabled -like $false}|Enable-SCOMAgentProxy
#To verify this one-liner has the desired effect, run the following one-liner, which returns a
#list of agents along with confirmation that agent proxy has been enabled.
Get-SCOMAgent |where {$_.ProxyingEnabled -like $true} | select Name, ProxyingEna-bled

#The Get-SCOMAgentApprovalSetting cmdlet fetches the AgentApprovalSetting for the #management group to which the OpsMgr PowerShell console is currently connected. It will #show either, Pending, AutoApprove, or AutoReject.
Get-SCOMAgentApprovalSettings

#The cmdlet Set-SCOMAgentApprovalSetting sets the AgentApprovalSetting for the #management group to which the OpsMgr PowerShell console is currently connected. The #three parameters are AutoApprove, AutoReject, and Pending. Here is an example to set the #agent approval setting for the management group to manual:
Set-SCOMAgentApprovalSetting -Pending
#To verify the changes were applied, run the following:
Get-SCOMAgentApprovalSetting

#Add custom alert resolution states
Add-SCOMAlertResolutionState -Name ‘OS Support’ -ResolutionStateCode 15
Add-SCOMAlertResolutionState -Name ‘Exchange Support’ -ResolutionStateCode 20
#To verify the alert resolution state changes, run the get-scomalertresolutionstate
Get-SCOMAlertResolutionState

#remove custom alert
Get-SCOMAlertResolutionState -Name ‘OS Support’ | Remove-SCOMAlertResolutionState

#Working with resource pools
Get-SCOMResourcePool -Name "Notifications Resource Pool" | GM
#changing the resourec pool
Get-SCOMResourcePool -Name “Notifications Resource Pool”|Set-SCOMResourcePool –EnableAutomaticMembership $FALSE
#how to verify settings changes
Get-SCOMResourcePool -DisplayName “Notifications Resource Pool” |FT Name, IsDynamic

#SCOM license mini-report
Get-SCOMAccessLicense | measure-object -property LogicalProcessorCount,PhysicalProcessorCount -sum | foreach {$_.Property + " Total : " + $_.Sum}

#How to retrieve a list of all object classes present in your Operations Manager 2012 #management group:
Get-SCOMClass| format-table DisplayName, Description
#Determine the management pack in which the class is defined:
Get-SCOMClass| format-table DisplayName, Description, ManagementPack
#Use the following to send this information to a csv file for easy reading in Excel:
Get-SCOMClass | select-object DisplayName, Description | export-csv -path c:\classes.csv
#Retrieving all the classes defined in a specific management pack is also a single line affair #with the following one-liner, which retrieves all the classes in the #Microsoft.SQLServer.Library management pack:
get-scomclass | where {$_.ManagementPackName -like ‘Microsoft.SQLServer.Library’}

#Exploring Discovered Instances
Get-SCOMClassInstance| select-object DisplayName, Name, Description

Get-SCOMClass -name "Microsoft.SQLServer.2012.Database" | Get-SCOMClassInstance

Get-SCOMClass -name "Microsoft.SQLServer.2012.Database" | Get-SCOMclassInstance | Format-Table DisplayName, PathName -auto

#Groups
#The Get-SCOMGroup cmdlet makes this an easy task, facilitating enumeration of group members in a single line of PowerShell, as shown in the following example.
Get-SCOMGroup -DisplayName "<DisplayName of Group>" | GetSCOMClassInstance
Get-SCOMGroup -DisplayName "<DisplayName of Group>" | GetSCOMClassInstance | export-csv D:\TEMP\groupmembers.csv -notypeinfo

#getting alerts related to a group
#found: http://sc.scomurr.com/scom-2012-getting-alerts-related-to-a-group-through-powershell/
$Group = Get-SCOMGroup -displayname ‘BLOG – My Application’
$ClassInstances = $Group.GetRelatedMonitoringObjects(‘Recursive’)
$Alerts = Get-SCOMAlert -instance $ClassInstances -ResolutionState (0..254)
$Alerts | ft Name

#Temporarily Disabling All Notification Subscriptions
Get-SCOMNotificationSubscription | where {$_.Enabled -eq $true} | Disable-SCOMNotificationSubscription

#Enable all notification subs
Get-SCOMNotificationSubscription | where {$_.Enabled -eq $false} | Enable-SCOMNotificationSubscription

#Report on Agent Primary Management Server and Failover Management Servers
Get-SCOMAgent|sort ComputerName|ft -a Computer-Name,primarymanagementservername,@{l="SecondaryManagementServers"; e={$_.getfailovermanagementservers()|foreach{$_.name}}}

#cool way of flushing a SCOM Agent Cache using powershell
#http://www.culham.net/powershell/flushing-a-scom-agent-cache-using-powershell/

#Add SCOM Subscribers the easy way

Add-SCOMNotificationSubscriber -Name ‘James Moss’ -DeviceList ‘james@contoso.com’,’sms:4048675309′,’sip:JIMMYjames’

COOL STUFF DUMP!

#Connect SCOM 2007 cmdlets to 2012 OM load snapin and run startup script
Add-PSSnapIn Microsoft.EnterpriseManagement.OperationsManager.Client
.\microsoft.enterprisemanagement.operationsmanager.clientshell.startup.ps1

# To Find out what the OperationsManager Cmdlets are
get-command -module OperationsManager

#Retrieve PowerShell Cmdlets and Parameters
Get-Command -Module OperationsManager | Select-Object -Property Name,@{Name=’Parameters';Expression={(Get-Command $_).Parameters.Keys}} | Sort Name

#Find out more about the OperationsManager Module
$mod=get-module OperationsManager
$mod | select * | more

#Help is also a great helper when you are trying to get familiar with new cmdlets
#I want to find out what cmdlets have SCOMALERT in their name
Get-help *SCOMALERT*
#Or what cmdlets have SCOMCLASS in their name
Get-help *SCOMCLASS*

#Get-Member is your friend to show you information about the objects cmdlets are bringing back
Get-SCOMAlerts | Get-Member
    #OR
Get-SCOMAlerts | GM
# you can pipe several cmdlets together and utilize GM to see the properties and methods available to the resulting objects
GET-SCOMAlerts |

#to limit what get-member brings back specify the member type to property
get-member -membertype property

#info about properties http://technet.microsoft.com/en-us/library/dd347654.aspx

#Ever wanted to know what you can pipe between cmdlets?  Say you are using the Get-#SCOMRule cmdlet to figure something about a SCOM Rule
#1) Pipe the Get-SCOMRule  Get-Member to find out the TypeName which is #Microsoft.EnterpriseManagement.Configuration.ManagementPackRule
#2) use get-command –ParameterType #Microsoft.EnterpriseManagement.Configuration.ManagementPackRule  to find out what #cmdlets will work with it.
#this piece of information came from Jeffery Snover from a MS TechEd video with Don Jones, I #think it was 2014 NA.
#But if you ever have to learn some new cmdlets from another module like Office 365 or Lync, #this could literally help you cut your learning curve in half by knowing
#what cmdlets can work together using the same types of data

get-command -ParameterType Microsoft.EnterpriseManagement.Configuration.ManagementPackRule

PS D:\> get-command -ParameterType Microsoft.EnterpriseManagement.Configuration.ManagementPackRule

CommandType     Name                                               ModuleName
———–     —-                                               ———-
Cmdlet          Disable-SCOMRule                                   OperationsManager
Cmdlet          Enable-SCOMRule                                    OperationsManager
Cmdlet          Get-SCOMEvent                                      OperationsManager
Cmdlet          Get-SCOMOverride                                   OperationsManager
Cmdlet          Get-SCOMOverrideResult                             OperationsManager

#another problem that you can run across when working with PowerShell is missing what #type of data a property is using
#an example that happened earlier this year is someone was trying to figure out how many #SCOM rules are enabled by default.
#so if you briefly look at the get-member output from get-scomrule you will notice that there #is a property called Enabled.
#going from my previous experience, and not looking at this information from Get-member, I #thought for sure it would be a Boolean value like $True or $False
Get-scomrule | GM
#enabled is actually a multiple value possibility 4 of which are True and False but it is not a #Boolean value but to get there is going to take some work…
get-scomrule | get-member -name Enabled

PS D:\> get-scomrule | get-member -name Enabled

   TypeName: Microsoft.EnterpriseManagement.Configuration.ManagementPackRule

Name    MemberType Definition
—-    ———- ———-
Enabled Property   Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitoringLevel Enabled {get;set;}

#BING Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitoringLevel
#Find the MPRULES properties http://msdn.microsoft.com/en-us/library/gg486202.aspx
#Then click on the link to the enumeration, which is

#http://msdn.microsoft.com/en-us/library/gg486379.aspx
#Scroll down to find the possible members of the enabled value which are:

#how to remove white space
$agent = Get-SCOMAgent
$agent | Group PrimaryManagementServerName -Noelement | sort Name | select Name, Count

#white space removed
$agent = Get-SCOMAgent
$agent | Group PrimaryManagementServerName -Noelement | sort Name | Format-Table Name, Count -auto

SCOM 2012 Daily Health Check Script

August 22, 2014 Leave a comment

First off this is an updated script from Jason Rydstrand’s SCOM 2007 R2 daily check script.  If you would like to check out the original please see http://blogs.technet.com/b/jasonrydstrand/archive/2013/03/27/daily-scom-health-check-with-powershell.aspx

Special shout out to Bob Cornelissen and Tao Yang on this script!

I’ve updated the commandlets so it can be used for SCOM 2012 and SCOM 2012 R2. This script is intended to use Gmail as the mail delivery method. It can be easily changed to use other email systems but I’ll save that for a future article.  The only part that will need to be modified is the following:

$UserName is your Gmail email account

$Password is your Gmail password

$mailmessage.from is who the email will be coming from

$mailmessage.To.Add can be any additional people you would like to send this email to.

 

script-gmail-config

Script is available for download at Microsoft TechNet Script Gallery: http://gallery.technet.microsoft.com/scriptcenter/SCOM-2012-Daily-Health-5950d801

One module to rule them all – a custom #scom managed module #sysctr

July 13, 2014 Leave a comment

Scott Moss:

Awesome!

Originally posted on Quae Nocent Docent:

One module to rule them all – a custom #scom managed module

During many years of MP development I faced cases where I would have loved the chance to pass a complete DataItem to a powershell module. There are many real world cases when you’d want to do that:

-You want to leverage the native OLEDB provider and you want to correlate multiple returned rows

-You need to use internal data sources that do not return property bags, but rather custom DataItems (for example the Microsoft.SystemCenter.GetWorkflowsReportProbe that can be used to query the agent for running and failed workflows)

-you need to take care of an entire walk from the standard SNMP modules and add logic to create your own data

-You don’t know how many properties the DataItem has in its payload and you want dynamically process them all

Today this is not possible for…

View original 1,117 more words

Categories: Uncategorized

Software-Defined Networking with Windows Server and System Center Jump Start

Two half-days – Wednesday July 16th & Thursday July 17th – 9am-1pm PST

Software-Defined Networking with Windows Server and System Center Jump Start

Free online event with live Q&A with the WAP team: http://aka.ms/WAPIaaS

IT Pros, you know that enterprises desire the flexibility and affordability of the cloud, and service providers want the ability to support more enterprise customers. Join us for an exploration of Windows Azure Pack’s (WAP’s) infrastructure services (IaaS), which bring Microsoft Azure technologies to your data center (on your hardware) and build on the power of Windows Server and System Center to deliver an enterprise-class, cost-effective solution for self-service, multitenant cloud infrastructure and application services.

Join Microsoft’s leading experts as they focus on the infrastructure services from WAP, including self-service and automation of virtual machine roles, virtual networking, clouds, plans, and more. See helpful demos, and hear examples that will help speed up your journey to the cloud. Bring your questions for the live Q&A!

Register here: http://aka.ms/WAPIaaS

Categories: WAP Tags:

The Windows Azure Pack (WAP) team is looking for some Feedback!

June 17, 2014 Leave a comment

This is going to be a link heavy post on all things WAP. The Building Clouds blog folks at (http://blogs.technet.com/b/privatecloud/) are putting out the word that they are looking for customer feedback on the WAP. Make suggestions and vote on the best suggestions.

The Feedback Link is http://feedback.azure.com/forums/255259-azure-pack

TechNet Link for WAP http://technet.microsoft.com/en-us/library/dn296435.aspx

WAP Wiki http://social.technet.microsoft.com/wiki/contents/articles/20689.the-windows-azure-pack-wiki-wapack.aspx

Forums Discussion WAP http://social.msdn.microsoft.com/Forums/windowsazure/en-US/home?forum=windowsazurepack

Just trying to do my part on getting the word out!

Scott Moss

Categories: WAP Tags:

OpsMgr Administration 101

Links from today’s presentation about OpsMgr Administration 101.

Hot Fixes for both Application and OS. Great blog article on this topic provided by Kevin Holman. Kevin does continue to update this page as new hot fixes are released. http://blogs.technet.com/b/kevinholman/archive/2009/01/27/which-hotfixes-should-i-apply.aspx

It is critical for a new SCOM Admin to understand that there are hot fixes needed for the SCOM Application as well as special OS level hot fixes that are needed after the agent has been deployed. It is best to deploy these hot fixes before deploying OpsMgr agents or infrastructure, b/c these hot fixes also apply to the SCOM infrastructure boxes.

OpsMgr Tools

Boris’s OpsMgr Tools – Updated (MP Viewer)
http://blogs.msdn.com/b/dmuscett/archive/2012/02/19/boris-s-tools-updated.aspx

Stefan Stranger’s System Center Operations Manager 2012 Toolbox
http://blogs.technet.com/b/stefan_stranger/archive/2012/09/30/system-center-operations-manager-2012-toolbox.aspx

MP Authoring Tools
http://technet.microsoft.com/en-us/library/hh457569.aspx

SCC Health Check MP Version 2 (Create new data source before importing the MP in SQL SRS see readme file)
http://www.systemcentercentral.com/pack-catalog/scc-health-check-management-pack-version-2/

MP Wiki (MP Diagrams and downloads)
http://mpwiki.viacode.com/

 

OpsMgr DBs

Use the OpsMgr planning excel file (see Stefan’s link above to download this file) to help calculate the OpsMgr DB sizes, and create the DBs to the Sizes’ requirements. The reason to do this is to avoid the SQL adding space to your database which will fragment your database as well as cause I/O overhead while the Database file is grown. Why would this be bad? OpsMgr is a very database I/O intensive application. Why add more overhead to SQL when you do not need to?

There should be at least 40% free space in the Operations Manager database.  Every night at 2 am a job runs to re-index certain tables. In order for this to run optimally and not fill up the database there should be at least 40%.

OpsMgr Reports from SCC Health Check Version 2!

I would suggest at a minimum having the following reports sent to your inbox on a daily basis and keep them in a folder to compare month to month changes in these metrics. Each of these reports can help trouble shoot possible issues in the future, i.e. after implementing a MP State Changes per day increases by 5000.

State – Noisiest Monitors (OM)
State – State Changes Per Day (OM)

Config Churn – Discoveries Last 24 Hours (DW)

Performance – Performance Inserts Per Day (OM)
Performance – Top 20 Performance Insertions By Perf (OM)

Events – All Events Count By Last 7 Days (OM)
Events – Top 20 Computers Generating the Most Events (OM)

Misc – Operational and Datawarehouse Usage Report (OM) – (DW)

Alerts – Number of Alerts per Day (OM)
Alerts – Top 20 Alerts By Alert Count (OM)

 

Alerts you can close

All alerts are not created equally. The only alerts that should be closed in the console are alerts generated by a Rule.

Alerts generated by a monitor should have the health of the monitor reset.

 

Configure System Center Advisor

https://www.systemcenteradvisor.com/DefaultPP5.aspx

Categories: Uncategorized

ATLSMUG User Group Meeting Friday 3/28/14 Register Now!

March 12, 2014 Leave a comment

We are finalizing the Agenda this week and I’ll post it once it is completed here. It should be a great meeting. If you are interested in attending please register for the event here, http://www.eventbrite.com/myevent?eid=10817697023 which is at the Microsoft Alpharetta facility.

Categories: ATLSMUG Tags:
Follow

Get every new post delivered to your Inbox.

Join 679 other followers