Wednesday, September 29, 2010

SCOM: Recipient address not valid - Find with PowerShell

One of the benefits of Operations Manager 2007 is the capability for users to create and maintain their own subscription notifications.

When a user adds a notification device to there recipient configuration, it's easy to make a small mistake. Whenever the Notifcation Server on the RMS trying to send a notification to a misconfigured address an alert is triggered, "Recipient address <address> is not valid."

The alert description shows in which subscription this address is used, but it's more important to know in which recipient this address can be found.

For that you can use this PowerShell script:

$searchcriteria = "yourtext"
Get-NotificationRecipient | foreach {
$addresses = $null;
$subname = $null;
$subname = $_.Name;
$addresses = $_.Devices | Where {
$_.Address -match $searchcriteria
}
if ($addresses -ne $null) {
Write-Host '***' $subname '***'; $addresses
}
}
As a one-liner:
$searchcriteria = "yourtext";Get-NotificationRecipient | foreach {$addresses = $null;$subname=$null;$subname = $_.Name;$addresses = $_.Devices | Where {$_.Address -match $searchcriteria }; if ($addresses -ne $null) { Write-Host '***' $subname '***'; $addresses}}

Monday, September 27, 2010

SCOM: Average Events Per Day keeps the doctor away


First of all, because I'm very busy with actually working on SCOM projects I can't spend the time blogging about SCOM as much as I would like.

But today I found some time to blog about a simple, but handy, SQL query I used to determine the average number of events stored in the Data Warehouse database per day.

At the base I used a query from Jonathan Almquist. Then I used that query as derative to count and calculate the average number of events per day. You can adjust the number of days, if you want.

select Count(Date) as 'Number Of Days', Avg(Events) As 'Average Number of Events'
From (
SELECT CONVERT(VARCHAR(10), DateTime, 101) AS Date, Count(*) AS Events
FROM Event.vEvent
WHERE (DateTime BETWEEN DATEADD(day, - 6, GETDATE()) AND GETDATE())
GROUP BY CONVERT(VARCHAR(10), DateTime, 101)
) x


So, what can you do with this?
Well, how do you know if your Management Servers can cache the event data collected by your agents when your Data Warehouse is down for a couple of hours.
Running these type of queries can help you understand how much data is stored in the Data Warehouse over time.

Tools like dwdatarp are also very helpfull to understand the data storage of the DWH.

Friday, July 30, 2010

SCOM: Operations Manager 2007 R2 Documentation


As I was browsing the Microsoft Technet site (most recent downloads) I came across a renewed documentation package for Operations Manager 2007 R2.

In this package you'll find everything you need for administering and authoring your OpsMgr environment, including XPlat! Also an easy way to complete your documentation library if it's not already up-to-date.

Here's a list with the contents:

  • Linked.Reporting.MP.xml
  • OM2007_AuthGuideXplat.exe
  • OM2007_ReportAuthoringGuide.docx
  • OM2007R2_CrossPlatformMPAuthoringGuide.docx
  • OM2007R2_CrossPlatformMPAuthoringGuide_Samples.zip
  • OM2007R2_DeploymentGuide.docx
  • OM2007R2_DesignGuide.docx
  • OM2007R2_MigrationGuide.docx
  • OM2007R2_MPAuthoringGuide.docx
  • OM2007R2_MPModuleReference.docx
  • OM2007R2_OperationsAdministratorsGuide.docx
  • OM2007R2_OperationsUsersGuide.docx
  • OM2007R2_SecurityGuide.docx
  • OM2007R2_UpgradeGuide.docx

If you want it all, just use the last download link

  • System Center Operations Manager 2007 R2 Documentation.zip

Microsoft's technet site: http://www.microsoft.com/downloads/details.aspx?FamilyID=19BD0EB5-7CA0-41BE-8C0F-2D95FE7EC636&displaylang=en

Even for the more experienced people there's a change already known documents are updated since the last time they were used in the field. So check it out.

Thursday, July 1, 2010

SCOM: Find those heavy group discoveries

Two days ago on the 'The Operations Manager Support Team Blog' a blog was posted about editing Groups and the slow Operation Manager Console. They advise to consolidate the number of membershiprules and expressions in regular expression.

But how do you know which groups are eligable for a consolidation? Well, for that I created this script.
It retrieves groups that comply with the given user input for the 'DisplayName'. For every group the Discovery information is retrieved. If the Discovery Configuration matches the prededined thresholds for the number of MembershipRules and/or Expressions, the output will be in red. Otherwise it will be in green. The threshold can be changed at will.

Download: ShowGroupDiscoveryDatasourceConfiguration.ps1

#User-input only works from within a script!
$strGroup = Read-Host "Enter a group discovery name (wildcard) string";

$intMembershipRuleThreshold = 3;
$intMembershipRuleExpressionThreshold = 5;
$intMembershipRuleCount = 0;
$intMembershipRuleExpressionCount = 0;

#These Id's are the base Id's which are usually used when creating groups
$strInstanceGroupBaseClassId = "4ce499f1-0298-83fe-7740-7a0fbc8e2449" #Instance group
$strComputerGroupBaseClassId = "0c363342-717b-5471-3aa5-9de3df073f2a" #Computer group

Write-Host "Retrieving class that match:" $strGroup;
$colGroups = Get-MonitoringClass | where {$_.DisplayName -match "$strGroup" -and $_.Base -ne $null} | Sort-Object -Property DisplayName

if ($colGroups -ne $null) {
$colGroups | foreach {
If (($_.Base.Id.ToString() -eq $strInstanceGroupBaseClassId) -Or ($_.Base.Id.ToString() -eq $strComputerGroupBaseClassId)){
Write-Host "Class:" $_.DisplayName;
$colDiscoveries = $_.GetMonitoringDiscoveries();
#check if discoveries exist
If ($colDiscoveries.Count -ne 0) {
$colDiscoveries | foreach {
Write-Host " Discovery:";
$config = [xml] ("" + $_.DataSource.Configuration + "");
#check wether Discovery uses membership rules
$intMembershipRuleCount = $config.GetElementsByTagName("MembershipRule").Count;
If($intMembershipRuleCount -gt 0){
If ($intMembershipRuleCount -ge $intMembershipRuleThreshold){
Write-Host " MembershipRules:" $intMembershipRuleCount -ForeGroundColor red;
} else {
Write-Host " MembershipRules:" $intMembershipRuleCount -ForeGroundColor green;
}
$intIndex = 0;
$config.config.MembershipRules.MembershipRule | %{
$intIndex++;
$intMembershipRuleExpressionCount = $_.GetElementsByTagName("Expression").Count;
If ($intMembershipRuleExpressionCount -gt 0) {
Write-Host " Membership Rule #$intIndex";
If ($intMembershipRuleExpressionCount -ge $intMembershipRuleExpressionThreshold){
Write-Host " Expression count:" $intMembershipRuleExpressionCount -ForeGroundColor red;
} else {
Write-Host " Expression count:" $intMembershipRuleExpressionCount -ForeGroundColor green;
}
}
$intMembershipRuleExpressionCount = 0;
}
}
$config = $null;
$intMembershipRuleCount = 0;
}
}
}
}
}
(ps. Save it as a script to use interactive User Input.)

Tuesday, June 29, 2010

SCOM: Agent Queue Size Script

A while ago I needed a script to adjust the SCOM Agent Queue size to make sure no auditing events were lost in case of a link failure between DC's and OpsMgr MS's.
So I created this script to do this for me.

If supports launching it from a Agent Task . The script gives a return code and quits before restarting the Health Service with a scheduled job, using 'at'.
Option Explicit
SetLocale("en-us")

Dim blnForceRestart
Dim lngValue
Dim strComputer
Dim strManagementGroup

Const HKEY_LOCAL_MACHINE = &H80000002
blnForceRestart = False
strComputer = "."


Call Main


Sub Main()

Call GetParams()
WScript.Echo "Executing " & WScript.ScriptName
Call RegChange()

End Sub



Sub RegChange()
Dim objReg
Dim lngCurrentValue
Dim strKeyPath
Dim strValueName

Set objReg = GetObject("winmgmts:\\" & strComputer &"\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Services\HealthService\Parameters\Management Groups\" & strManagementGroup
strValueName = "MaximumQueueSizeKb"

objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, lngCurrentValue

If IsNull(lngCurrentValue) Then
WScript.Echo "An error occured while reading registry key."
WScript.Quit 201
End If

If CLng(lngCurrentValue) <> lngValue Then
objReg.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, lngValue
WScript.Echo strValueName & ": " & lngCurrentValue & " changed to " & lngValue
Call ScheduleRestartHealthService()
Else
WScript.Echo "Current value '" & lngCurrentValue & "' matches parameter value: " & lngValue
If blnForceRestart Then
WScript.Echo "Restart of HealthService forced."
Call ScheduleRestartHealthService()
End If
End If
End Sub



Sub ScheduleRestartHealthService()
Dim dtmTime
Dim dtmScheduleTime
Dim objShell
Dim intMinutesDelay
Dim intReturn

Set objShell = CreateObject("Wscript.Shell")
dtmTime = Now()
If Second(dtmTime) < 50 Then
intMinutesDelay = 1
Else
intMinutesDelay = 2
End If
dtmScheduleTime = FormatDateTime(DateAdd("n",intMinutesDelay,dtmTime),4)
WScript.Echo "Scheduling a HealthService restart for " & dtmScheduleTime
intReturn = objShell.Run("at " & dtmScheduleTime & " cmd /c " & Chr(34) &_
"net stop healthservice && net start healthservice",0,False)
If intReturn > 0 Then WScript.Quit Clng(intReturn + 500)
End Sub

Sub GetParams()
If Wscript.Arguments.Named("mgmtgrp") <> "" Then
strManagementGroup = Wscript.Arguments.Named("mgmtgrp")
Else
WScript.Echo "Missing 'mgmtgrp' argument"
WScript.Quit 101
End If

If WScript.Arguments.Named("sizekb") <> "" Then
lngValue = CLng(WScript.Arguments.Named("sizekb"))
Else
lngValue = 15360 'Default value
WScript.Echo "Using default Queue Size, " & lngValue & " kB."
End If

If WScript.Arguments.Named.Exists("forcerestart") Then
blnForceRestart = True
End If
End Sub

Thursday, June 24, 2010

SCOM: System Center Operations Manager R2 Unleashed - Review - A GREAT Supplement

A few weeks ago I got my copy of the supplement to the book 'System Center Operations Manager 2007 Unleashed', called 'System Center Operations Manager 2007 R2 Unleashed'.

I love the 'Unleashed' books for SCCM and SCOM and couldn't wait to get my hands on this one. As I blogged a while ago, this book contains a lot of updates compared to the first book. This blogpost is a my personal review about the contents and as far as I know my first public book review.

This book is writen by the same authors as it's big brother. Along with many other SCOM specialists they managed to create a very useful and practical technical add-on. It's really loaded with in-depth information.

Why I think you should get this book:
  • A lot of best practices & examples
  • A convenient and clear summary of updates/changes on SCOM since its introduction
  • A great chapter about X-plat/Cross-platform monitoring, including a walkthrough and examples with 3rd party management packs!
  • All you need to know about Windows 2008 and System Center Operations Manager R2, it's there
  • Nice writing about upgrading SQL 2005 to SQL 2008
  • Everything you need/wanted to know about the OpsMgr PowerShell Extensions
    Including: practical documentation, examples and performance enhancements
  • A virtualization update about managing virtual infrastructures
  • Nice chapter about MP Authoring. I think this can help a lot of SCOM admins with creating management packs.
Pros:
  • Many best-practices SCOM admins can find on the web are finally grabbed together in this "fat pocket guide"
  • Nice examples (SQL queries & Powershell)
  • Cross-platform in a nutshell
  • It's clearly visible the authors worked together with the known MVP's and other specialists. The MP cook down practices are a great example of this.
  • The book has answers to most of the questions that can arise with managing SCOM, like performance, scaling, backup & recovery.
  • Nice appendix with more up-to-date MP tuning tips (compilation of ops-mgr.spaces.live.com which moved to http://systemcentercentral.com/byexample)
Small ;) Cons:
  • VMM promo. The virtualization chapter takes the reader along the features of VMM integration with OpsMgr. It's a nice promo & walkthrough, but it would be nice to also see more of Bridgeway's of Veeam's MP. I must say the authors did a great job showing some features of the VMM MP, of which you could benefit when you use VMware virtualization technology without vCenter. (I think this could be an item of the pros list ;) )
  • The pages could use some chapter - paragraph header info. Because of the information load, it's nice to know where you're at :D (like the original book)
  • I think adding extra in-depth information about creating and using Reports is the last item that's missing for a SCOM admin to be fully equiped. This book contains a paragraph about the R2 enhancements and using a linked report in the Authoring Console. It would be nice to add some best-practices/guides about getting more from the Reporting feature like they did in the chapter about the PowerShell Extensions chapter. More examples like in the previous book would be nice!
  • On page 13 it states the R2 version of the Windows Service Management Pack template enables wildcard entry to select multiple, similarly named services. I'm still searching for this, but haven't been able to use wildcards with this template besides using the WmiProviderWithClassSnapshotDataMapper.

Book 'Rollup': Very Healthy

Great book for every SCOM admin and author. I think this is a piece of equipment every SCOM admin should have in his/her toolbox. Along with the 'System Center Operations 2007 Unleashed' book of course.

Friday, June 4, 2010

SCOM: Get-UserRole Views (PowerShell)

Currently I'm working on a OpsMgr Shell script to output the allowed Views for User Roles.

Current status: Working from User Role perspective to output views. Too bad, the folder hierarchy has to build from another perspective. There's a challenge!
$mgmtgrp = (Get-ManagementGroupConnection).ManagementGroupGet-UserRole | Select -First 1 | foreach { If($_.IsScopeFixed -ne $true){Write-Host "--"$_.DisplayName"--"$_.Scope.MonitoringViews | foreach { $arrViews += @($mgmtgrp.GetMonitoringView($_.First).DisplayName)}$arrViews = $arrViews | Sort-Object$arrViews$arrViews = $null}}

Wednesday, June 2, 2010

Syntax Highlighting Feature

I'm running this blog for 1,5 years now, and I thought it was time to add a little bling feature.

$message = "So, for better readability,"

Dim strMessage="from now on all my code examples..."

are presented with syntax highlighting"
    Cool features
  • syntax highlighing for a lot of different code types: see here

  • code view

  • code copy

  • code printing

See SyntaxHighlighter for more information.

Powershell Example:
# SCOM Shell Script
#Returns all User Roles matching given DisplayName and show the User Role members
Get-UserRole | Where {$_.DisplayName -match "Operator Team X"} | Sort-Object DisplayName | foreach { Write-Host "Role:" $_.DisplayName ; $_.Users | foreach { Write-Host " $_"}}

To view all code items use #Code label.