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.