<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Tao Yang's System Management Blog</title>
	
	<link>http://blog.tyang.org</link>
	<description>My thoughts on SCOM, SCCM, PowerShell and more...</description>
	<lastBuildDate>Wed, 01 Feb 2012 22:34:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TaoYangsSystemManagementBlog" /><feedburner:info uri="taoyangssystemmanagementblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>SCCM Report: Site Boundaries</title>
		<link>http://blog.tyang.org/2012/02/02/sccm-report-site-boundaries/</link>
		<comments>http://blog.tyang.org/2012/02/02/sccm-report-site-boundaries/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 22:34:48 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCCM]]></category>
		<category><![CDATA[SCCM Reports]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=978</guid>
		<description><![CDATA[I wrote this simple report yesterday to list and search site boundaries: Report Name: SCCM Site Boundaries SQL Query: &#160; Prompts: Name: BoundaryName Prompt Text: Boundary Name Prompt SQL Statement:]]></description>
			<content:encoded><![CDATA[<p>I wrote this simple report yesterday to list and search site boundaries:</p>
<p>Report Name: SCCM Site Boundaries</p>
<p><strong>SQL Query:</strong></p>
<pre class="brush: sql; title: ; notranslate">
SELECT distinct
v_BoundaryInfo.DisplayName AS [Boundary Name],
Case v_BoundaryInfo.BoundaryType
When 0 then 'IP Subnet'
When 1 then 'AD Site'
When 2 then 'IPV6 Prefix'
When 3 then 'IP Range'
End As 'Type',
v_BoundaryInfo.Value AS [Value],
v_BoundaryInfo.SiteCode AS [Site Code]
From v_BoundaryInfo WHERE DisplayName LIKE @BoundaryName
</pre>
<p>&nbsp;</p>
<p><strong>Prompts:</strong></p>
<p>Name: BoundaryName</p>
<p>Prompt Text: Boundary Name</p>
<p>Prompt SQL Statement:</p>
<pre class="brush: sql; title: ; notranslate">
begin
if (@__filterwildcard = '')
Select DisplayName from v_BoundaryInfo order by DisplayName
else
Select DisplayName from v_BoundaryInfo where DisplayName LIKE @__filterwildcard order by DisplayName
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2012/02/02/sccm-report-site-boundaries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SCCM Health Check Script Updated: Version 3.5</title>
		<link>http://blog.tyang.org/2012/01/31/sccm-health-check-script-updated-version-3-5/</link>
		<comments>http://blog.tyang.org/2012/01/31/sccm-health-check-script-updated-version-3-5/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 09:55:11 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCCM]]></category>
		<category><![CDATA[Health Check]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=973</guid>
		<description><![CDATA[I have just updated the SCCM Health Check Script to from version 3.3 to 3.5 Version 3.4 was finished a while back but I never got time to publish it in this blog. I only emailed 3.4 to few people who contacted me from my blog. Now that I’ve updated it again to 3.5, I [...]]]></description>
			<content:encoded><![CDATA[<p>I have just updated the <a title="SCCM Health Check Script" href="http://blog.tyang.org/2011/03/30/powershell-script-sccm-health-check/">SCCM Health Check Script </a>to from version 3.3 to 3.5</p>
<p>Version 3.4 was finished a while back but I never got time to publish it in this blog. I only emailed 3.4 to few people who contacted me from my blog. Now that I’ve updated it again to 3.5, I thought I’ll just publish version 3.5.</p>
<h2><span style="color: #ff0000;">What’s Changed Since 3.3?</span></h2>
<ol>
<li>Added site system name under &#8216;site systems with issues&#8217; section</li>
<li>Detect site components that are missing heartbeats.</li>
<li>Changed function Validate-DNSRecord to use Win32_ComputerSystem.caption rather than DNSHostname to retrieve computer name as DNSHostName is not available on computers before Windows 2008.</li>
</ol>
<h2><span style="color: #ff0000;">Update Instruction</span></h2>
<p>A new item has been added to the configuration XML (Health-Check.xml):<br />
<span style="color: #ff0000;">   &lt;MaxMissingHeartBeatTolerance&gt;<br />
&lt;Hours&gt;24&lt;/Hours&gt;<br />
&lt;/MaxMissingHeartBeatTolerance&gt;</span></p>
<p>As the name suggest, the script raises any site systems as problematic if it has not sent heartbeat for over the X number of hours that you configured in XML (in my example, it’s 24 hours).</p>
<p>You may keep the old XML that you have already configured for your environment as long as you add the following lines in the Health-Check.XML:</p>
<p>&nbsp;</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image62.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb62.png" alt="image" width="532" height="314" border="0" /></a></p>
<p>You can download version 3.5 <span style="font-size: medium;"><strong><a href="http://blog.tyang.org/wp-content/uploads/2012/01/SCCM-Health-Check-v3.5.zip">HERE</a></strong></span>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2012/01/31/sccm-health-check-script-updated-version-3-5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Command Line Parameters for SCOM Command Notification Channel</title>
		<link>http://blog.tyang.org/2012/01/29/command-line-parameters-for-scom-command-notification-channel/</link>
		<comments>http://blog.tyang.org/2012/01/29/command-line-parameters-for-scom-command-notification-channel/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 06:53:17 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SCOM]]></category>
		<category><![CDATA[Command Notification]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=962</guid>
		<description><![CDATA[Few years ago, I wrote the Enhanced SCOM Alert Notification script and I blogged it here. In all the environments that I implemented this script in command notification channel, there were always some random alerts not been processed. Few months ago, I was working on another PowerShell script to be used in command notification channel [...]]]></description>
			<content:encoded><![CDATA[<p>Few years ago, I wrote the Enhanced SCOM Alert Notification script and I blogged it <a href="http://blog.tyang.org/2010/07/19/enhanced-scom-alerts-notification-emails/">here</a>.</p>
<p>In all the environments that I implemented this script in command notification channel, there were always some random alerts not been processed.</p>
<p>Few months ago, I was working on another PowerShell script to be used in command notification channel to update a custom field when alerts are created. While I was testing it, I found it has exactly the same problem, the subscription randomly skips alerts and left them not processed.</p>
<p>In the end, I found the cause of the problem: the command line parameters are not configured properly! The details can be found in Steve Rachui’s blog article here: <a href="http://blogs.msdn.com/b/steverac/archive/2010/08/17/updating-custom-alert-fields-using-subscriptions-and-powershell.aspx">Updating custom alert fields using subscriptions and powershell</a>. Steve explained in the article:</p>
<blockquote><p>There are several quotation marks in the command line so I’ve listed the text again below in case you want to copy/paste in your environment. Note the highlights above – these are single quotes that go around alert ID as it’s passed to the script. Make sure you include these because if you don’t the alert ID won’t be handled correctly in all cases and the script will not run consistently.</p>
<p>Full path of the command file: <em>c:\windows\system32\windowspowershell\v1.0\powershell.exe<br />
</em><strong>Command line parameters: </strong><em><strong>-Command &#8220;&amp; &#8216;&#8221;C:\alertupdater.ps1&#8243;&#8216;&#8221; &#8216;$Data/Context/DataItem/AlertId$&#8217;<br />
</strong></em>Startup folder for the command line: <em>c:\windows\system32\windowspowershell\v1.0\</em></p></blockquote>
<p>So to fix my problem with my Ehanced SCOM Alert Nofication Script, the command line parameter should be:</p>
<p><strong><span style="color: #ff0000;">-Command &#8220;&amp; &#8216;&#8221;D:\Scripts\SCOMEnhancedEmailNotification.ps1&#8243;&#8216;&#8221; -alertID &#8216;$Data/Context/DataItem/AlertId$&#8217; -Recipients @(&#8216;Tao Yang;Tao.Yang@xxxx.com’,John Smith;John.Smith@xxxx.com‘)</span></strong></p>
<p><strong>I’ve updated the original Enhanced SCOM Alerts Notification EMails blog article to reflect this change.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2012/01/29/command-line-parameters-for-scom-command-notification-channel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SCOM: Monitoring an Interactive Process and The Recovery Task</title>
		<link>http://blog.tyang.org/2012/01/28/scom-monitoring-an-interactive-process-and-the-recovery-task/</link>
		<comments>http://blog.tyang.org/2012/01/28/scom-monitoring-an-interactive-process-and-the-recovery-task/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 22:37:52 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCOM]]></category>
		<category><![CDATA[MP Authoring]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=946</guid>
		<description><![CDATA[Recently I’m working on a management pack for a series of apps for a business unit of my employer. There is a large number of processes that I need to monitor and they run interactively on the console session. Auto Admin Logon is enabled on these servers, when the server starts up, it automatically logged [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I’m working on a management pack for a series of apps for a business unit of my employer. There is a large number of processes that I need to monitor and they run interactively on the console session. Auto Admin Logon is enabled on these servers, when the server starts up, it automatically logged on using the account configured and the the interactive processes are automatically started.</p>
<p>Setting up monitors for these processes is easy. However, I went a step further and created a generic write action module to be used as recovery task that restarts the process interactively on the console session.</p>
<p>There is one pre-requisite for the recovery task: I had to use PsExec to launch the process on console session. PsExec can be downloaded here: <a href="http://technet.microsoft.com/en-us/sysinternals/bb897553">http://technet.microsoft.com/en-us/sysinternals/bb897553</a>. PsExec needs to be copied locally to the computers that are being monitored.</p>
<p>I’ll now use use an example to go through how I setup the monitor, write action module and recovery task for notepad.exe</p>
<p><strong><span style="color: #ff0000;">01.</span></strong> First of all, I created a class and its discovery to target my test machine “Client01”</p>
<p><strong><span style="color: #ff0000;">02.</span></strong> Added “Microsoft.SystemCenter.ProcessMonitoring.Library” as a reference in my MP.</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image40.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb40.png" alt="image" width="481" height="477" border="0" /></a></p>
<p><span style="color: #ff0000;">03.</span> Created a process monitor for notepad.exe</p>
<ul>
<ul>
<li><strong>Monitor Type:</strong> Process Instance Count Monitor Type (from “Microsoft.SystemCenter.ProcessMonitoring.Library”)</li>
<li><strong>Monitor Configuration:</strong></li>
<li></li>
</ul>
</ul>
<table width="600" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="444">ProcessName</td>
<td valign="top" width="156">notepad.exe</td>
</tr>
<tr>
<td valign="top" width="444">Frequency</td>
<td valign="top" width="156">60</td>
</tr>
<tr>
<td valign="top" width="444">MinInstanceCount</td>
<td valign="top" width="156">1</td>
</tr>
<tr>
<td valign="top" width="444">MaxInstanceCount</td>
<td valign="top" width="156">1</td>
</tr>
<tr>
<td valign="top" width="444">InstanceCountOutOfRangeTimeThresholdInSeconds</td>
<td valign="top" width="156">5</td>
</tr>
</tbody>
</table>
<ul>
<li><span style="color: #ff0000; font-size: small;"><strong>Note:</strong></span> While I was setting up the monitor, I realised the process name is case sensitive. Also, Frequency is in seconds</li>
<li><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image41.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb41.png" alt="image" width="550" height="273" border="0" /></a></li>
<li>This is pretty much the same as using the Process Monitoring template from from the SCOM operations console (under Authoring Pane) – Except I used my own class rather than targeting to a group. Below is from the process monitoring wizard:</li>
<li><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image42.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb42.png" alt="image" width="537" height="395" border="0" /></a></li>
</ul>
<p><strong><span style="color: #ff0000;">04.</span></strong> Now once I import the MP into my SCOM management group, I can verify it is working (from health explorer):</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image43.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb43.png" alt="image" width="580" height="474" border="0" /></a></p>
<p align="left"><strong><span style="color: #ff0000;">05.</span></strong> Because the way this monitor works, it is only healthy when the process count is in between MinInstanceCount and MaxInstanceCount (both set to 1 in this case). So the monitor’s health turns to Errorif there are say 2 instance of notepad running. Therefore I need to run a diagnostic task to determine how many instances are actually running because I only want to run the recovery task when the instance count is less than 1. I created a diagnostic task to run when the monitor’s health is in Error state. This diagnostic has only 1 action module: <strong>“Microsoft.Windows.ScriptPropertyBagProbe”:</strong></p>
<p align="left"><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image44.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb44.png" alt="image" width="544" height="535" border="0" /></a></p>
<ul>
<ul>
<li>
<div align="left"><strong>Module configuration:</strong></div>
</li>
<li>
<table width="600" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="300">ScriptName</td>
<td valign="top" width="300">CheckProcessDiagnostic.vbs</td>
</tr>
<tr>
<td valign="top" width="300">Arguments</td>
<td valign="top" width="300">notepad.exe</td>
</tr>
<tr>
<td valign="top" width="300">ScriptBody</td>
<td valign="top" width="300">refer to the vbscript below</td>
</tr>
<tr>
<td valign="top" width="300">TimeoutSeconds</td>
<td valign="top" width="300">60</td>
</tr>
</tbody>
</table>
</li>
<li>
<div align="left">Here’s the script:</div>
</li>
</ul>
</ul>
<pre class="brush: vb; title: ; notranslate">
'==========================================
' AUTHOR:            Tao Yang
' Script Name:        CheckProcessDiagnostic.vbs
' DATE:                27/01/2012
' Version:            1.0
' COMMENT:            - Script to check process state.
'                    - Used for OpsMgr Management Pack diagnostic tasks.
'==========================================
ProcessName = WScript.Arguments.Item(0)
Set oAPI = CreateObject(&quot;MOM.ScriptAPI&quot;)
Set oBag = oAPI.CreatePropertyBag()
WMIQuery = &quot;Select * From Win32_process WHERE name = '&quot; + ProcessName + &quot;'&quot;
Set objWMIService = GetObject(&quot;winmgmts:\\.\root\cimv2&quot;)
Set colProcesses = objWMIService.ExecQuery (WMIQuery)
Call oBag.AddValue(&quot;ProcessName&quot;,ProcessName)
If colProcesses.count &amp;lt; 1 Then
Call oBag.AddValue(&quot;Result&quot;,&quot;Positive&quot;)
Else
Call oBag.AddValue(&quot;Result&quot;,&quot;Negative&quot;)
End If
oAPI.Return(oBag)
</pre>
<ul>
<li>This script returns a property bag variable“Result”. The value of “Result” is “Positive” if there is less than 1 instance of notepad.exe running. otherwise, the value is “Negative”. I will use the the value of “Result” to determine whether to run the recovery task or not by using a condition detection module in recovery task later.</li>
</ul>
<p><strong><span style="color: #ff0000;">06.</span></strong> Create a Write Actions module for the recovery task. I’m creating a separate module for this so I can use it in recovery tasks of multiple monitors.</p>
<ul>
<ul>
<li><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image45.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb45.png" alt="image" width="522" height="514" border="0" /></a></li>
<li>Member Module: <strong>“Microsoft.Windows.PowerShellWriteAction”</strong></li>
<li><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image46.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb46.png" alt="image" width="545" height="536" border="0" /></a></li>
<li><strong>Module Configuration:</strong></li>
<li><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image47.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb47.png" alt="image" width="719" height="683" border="0" /></a></li>
<li>While editing this module, Add below secion between &lt;/ScriptBody&gt; and &lt;/Configuration&gt;:</li>
</ul>
</ul>
<p><span style="color: #ff0000;">&lt;Parameters&gt;<br />
&lt;Parameter&gt;<br />
&lt;Name&gt;PsExecPath&lt;/Name&gt;<br />
&lt;Value&gt;$Config/PsExecPath$&lt;/Value&gt;<br />
&lt;/Parameter&gt;<br />
&lt;Parameter&gt;<br />
&lt;Name&gt;PathToExe&lt;/Name&gt;<br />
&lt;Value&gt;$Config/PathToExe$&lt;/Value&gt;<br />
&lt;/Parameter&gt;<br />
&lt;Parameter&gt;<br />
&lt;Name&gt;Context&lt;/Name&gt;<br />
&lt;Value&gt;$Config/Context$&lt;/Value&gt;<br />
&lt;/Parameter&gt;<br />
&lt;Parameter&gt;<br />
&lt;Name&gt;Arguments&lt;/Name&gt;<br />
&lt;Value&gt;$Config/Arguments$&lt;/Value&gt;<br />
&lt;/Parameter&gt;<br />
&lt;/Parameters&gt;<br />
&lt;TimeoutSeconds&gt;$Config/TimeoutSeconds$&lt;/TimeoutSeconds&gt;</span></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image48.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb48.png" alt="image" width="545" height="385" border="0" /></a><br />
Place the PowerShell script below between &lt;ScriptBody&gt;&lt;/ScriptBody&gt; section:</p>
<pre class="brush: powershell; title: ; notranslate">
#=================================================
# AUTHOR:  Tao Yang
# DATE:    16/01/2012
# Version: 1.0
# COMMENT: Start a exe on console session under LocalSystem Context
#=================================================

param([string]$PsExecPath, [string]$PathToExe, [string]$Context, [string]$Arguments)
# $Context should have only 2 possible values: &quot;System&quot; or &quot;User&quot;. &quot;User&quot; needs Auto Admin Logon Enabled
Function Get-ConsoleSessionInfo
{
$results = Query Session
$ConsoleSession = $results | select-string &quot;console\s+(\w+)\s+(\d+)\s+(\w+)&quot;
if ($ConsoleSession)
{
$UserName = $ConsoleSession.Matches[0].groups[1].value
$SessionID = $ConsoleSession.Matches[0].groups[2].value
$State = $ConsoleSession.Matches[0].groups[3].value
$objConsoleSession = New-Object psobject
Add-Member -InputObject $objConsoleSession -Name &quot;UserName&quot; -Value $UserName -MemberType NoteProperty
Add-Member -InputObject $objConsoleSession -Name &quot;SessionID&quot; -Value $SessionID -MemberType NoteProperty
Add-Member -InputObject $objConsoleSession -Name &quot;State&quot; -Value $State -MemberType NoteProperty
} else { $objConsoleSession = $null }
Return $objConsoleSession
}

$Mode = $null
#Determine UserID
If ($Context -ieq &quot;User&quot;)
{
$strUserName = $null
$DefaultPassword = $null
#detect if auto admin is enabled, if so, retrieve username and password from registry
$WinlogonRegKey = get-itemproperty &quot;HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\&quot;
If ($WinlogonRegKey.AutoAdminLogon = &quot;1&quot;)
{
$DefaultUserName = $WinlogonRegKey.DefaultUserName
$DefaultDomainName = $WinlogonRegKey.DefaultDomainName
$DefaultPassword = $WinlogonRegKey.DefaultPassword
$strUserName = &quot;$DefaultDomainName`\$DefaultUserName&quot;
}

If ($strUserName -and $DefaultPassword)
{
$Mode = &quot;User&quot;
} else {
Write-Error &quot;Owner variable set to `&quot;User`&quot; but Auto Admin Logon is not configured!&quot;
}
} elseif ($Context -ieq &quot;System&quot;) {
$Mode = &quot;System&quot;
} else {
Write-Error &quot;Incorrect Owner variable. it can only be `&quot;User`&quot; or `&quot;System`&quot;&quot;
}

#$thisScript = Split-Path $myInvocation.MyCommand.Path -Leaf
#$scriptRoot = Split-Path(Resolve-Path $myInvocation.MyCommand.Path)
#$PsExecPath = Join-Path $scriptRoot &quot;PsExec.exe&quot;
If (!(Test-Path $PsExecPath))
{
Write-Error &quot;Unable to locate PsExec.exe in $scriptRoot. Please make sure it is located in this directory!&quot;
} else {
#Get Console Session ID
$ConsoleSessionID = (Get-ConsoleSessionInfo).SessionID
if ($ConsoleSessionID)
{
If ($Mode -eq &quot;User&quot;)
{
$strCmd = &quot;$PsExecPath -accepteula -i $ConsoleSessionID -d -u $strUsername -p $DefaultPassword $PathToExe $arguments&quot;
Write-Host &quot;Executing $strCmd`...&quot;
Invoke-Expression $strCmd
} elseif ($Mode -eq &quot;System&quot;) {
$strCmd = &quot;$PsExecPath -accepteula -i $ConsoleSessionID -d -s $PathToExe $arguments&quot;
#run app under LOCALSYSTEM context
Write-Host &quot;Executing $strCmd`...&quot;
Invoke-Expression $strCmd
}
} else {
Write-Error &quot;No one is currently logged on to the console session at the moment.&quot;
}
}
</pre>
<p><span style="color: #ff0000;"><strong>Note:</strong></span>this PowerShell script uses command “query session” to detect the session ID of the console session.</p>
<p><span style="color: #ff0000;"><strong>Note:</strong></span> When you save the configuration of this module, please <strong>ignore</strong> this error:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image49.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb49.png" alt="image" width="445" height="206" border="0" /></a></p>
<p>Add the following item under Configuration Schema tab:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image50.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb50.png" alt="image" width="545" height="547" border="0" /></a></p>
<p><strong><span style="color: #ff0000;">Note: </span></strong>Make sure “TimeoutSeconds” type is set to “Integer” and others are set to “String”</p>
<p>I also defined “TimeoutSeconds” as an overridable paramter:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image51.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb51.png" alt="image" width="545" height="234" border="0" /></a></p>
<p>Finally, set the Accessibility to Public (so it can be used in other management pack once this management pack is sealed&#8221;):</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image52.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb52.png" alt="image" width="545" height="175" border="0" /></a></p>
<p><strong><span style="color: #ff0000;">07.</span></strong> Create a recovery task to run after Diagnostic Task that I created from the step 5.</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image53.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb53.png" alt="image" width="479" height="475" border="0" /></a></p>
<ul>
<li>This recovery task has 2 modules: a condition detection module (System.ExpressionFilter) and an Actions module (From the Write Actions module I created from Step 6)</li>
</ul>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image54.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb54.png" alt="image" width="525" height="523" border="0" /></a></p>
<ul>
<ul>
<li><strong>Condition Detection Module (System.ExpressionFilter):</strong></li>
<li><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image55.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb55.png" alt="image" width="593" height="562" border="0" /></a></li>
<li>Click Edit and add below:</li>
</ul>
</ul>
<p><span style="color: #ff0000;">&lt;Expression&gt;<br />
&lt;SimpleExpression&gt;<br />
&lt;ValueExpression&gt;<br />
&lt;XPathQuery Type=&#8221;String&#8221;&gt;Diagnostic/DataItem/Property[@Name='Result']&lt;/XPathQuery&gt;<br />
&lt;/ValueExpression&gt;<br />
&lt;Operator&gt;Equal&lt;/Operator&gt;<br />
&lt;ValueExpression&gt;<br />
&lt;Value Type=&#8221;String&#8221;&gt;Positive&lt;/Value&gt;<br />
&lt;/ValueExpression&gt;<br />
&lt;/SimpleExpression&gt;<br />
&lt;/Expression&gt;</span></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image56.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb56.png" alt="image" width="545" height="184" border="0" /></a></p>
<p><strong>Actions Module (Module Type from the write action module created in Step 6)</strong></p>
<table width="600" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="143">PsExecPath</td>
<td valign="top" width="457">Path to PsExec.exe on the target computer</td>
</tr>
<tr>
<td valign="top" width="143">PathToExe</td>
<td valign="top" width="457">The executable that you want PsExec to run</td>
</tr>
<tr>
<td valign="top" width="143">Context</td>
<td valign="top" width="457">2 Possible values: “User” or “System”</td>
</tr>
<tr>
<td valign="top" width="143">Argument</td>
<td valign="top" width="457">arguments for the executable that PsExec is executing</td>
</tr>
<tr>
<td valign="top" width="143">TimeoutSeconds</td>
<td valign="top" width="457"></td>
</tr>
</tbody>
</table>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image57.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb57.png" alt="image" width="545" height="331" border="0" /></a></p>
<p><strong><span style="color: #ff0000;">Note:</span></strong> Regarding to the Context variable, I designed the script to launch PsExec to execute the executable either under LOCALSYSTEM (  with –s  operator in PsExec) or under the user that’s configured for Auto Admin Logon (with –u &lt;username&gt; and –p &lt;password&gt; operators in PsExec). Because when Auto Admin Logon is enabled, the default username and password is stored in the registry key (<strong>HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon</strong>). If “Context” is set to “User”, the script reads the username and password from registry and pass them into PsExec. So, if Auto Admin Logon is not configured, the script won’t work if “Context” is set to “User”</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image58.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb58.png" alt="image" width="545" height="259" border="0" /></a></p>
<p><strong><span style="color: #ff0000;">Note:</span></strong> In this example, the recovery task simply launch notepad.exe on the console session. I can also tell notepad to open a txt file if I add the path of the txt file to “Arguments”.</p>
<p><strong><span style="color: #ff0000;">Note:</span></strong> This recovery task will error out if no one has logged on to the console session of the target computer.</p>
<p>Now, everything is setup, time to put it to test.</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image59.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb59.png" alt="image" width="545" height="482" border="0" /></a></p>
<p>From screen capture below, I can see the monitor’s health became Error at 10:44pm 27/01/2012. After the Diagnostic task determined there is no notepad.exe running, the recovery task kicks in, at 10:45pm, it launched notepad.exe on console session (session ID 2). The PID of notepad.exe is 4000.</p>
<p>Now, when I go to the target computer, notepad is launched on the console session and I can easily get the details of notepad.exe process:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/notepad.png"><img class="alignleft  wp-image-956" title="notepad" src="http://blog.tyang.org/wp-content/uploads/2012/01/notepad-300x252.png" alt="" width="498" height="335" /></a></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image60.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb60.png" alt="image" width="545" height="464" border="0" /></a></p>
<p>You can see from above screen capture, notepad.exe was started at the same time when the recovery task ran, the session ID is 2, Owner is the account configured for Auto Admin Logon and process ID is same as the output from PsExec. Therefore, this instance of notepad.exe is the one started by the recovery task!</p>
<p>I’ve attached the 2 scripts used in Diagnostic and recovery tasks below. as well as my sample unsealed MP.</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/Custom.Interactive.Process.Monitoring.zip">Download From Here</a></p>
<p>Please feel free to contact me if you have any questions or suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2012/01/28/scom-monitoring-an-interactive-process-and-the-recovery-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SCOM: Process Performance Collection Rule for Services</title>
		<link>http://blog.tyang.org/2012/01/27/scom-process-performance-collection-rule-for-services/</link>
		<comments>http://blog.tyang.org/2012/01/27/scom-process-performance-collection-rule-for-services/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 02:28:08 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCOM]]></category>
		<category><![CDATA[MP Authoring]]></category>
		<category><![CDATA[PerfMon]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=888</guid>
		<description><![CDATA[Setting up Performance Collection rules for a particular process is pretty straightforward in SCOM. However, the it has it’s limitations. Process performance collections rules are straightforward to setup, as long as there is ONLY ONE instance of the particular process running on the computers that your rule is targeting. Also, each rule can only collect [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up Performance Collection rules for a particular process is pretty straightforward in SCOM. However, the it has it’s limitations.</p>
<p>Process performance collections rules are straightforward to setup, as long as there is ONLY ONE instance of the particular process running on the computers that your rule is targeting. Also, each rule can only collect ONE performance counter.</p>
<p>The problem with that is, if I need to collect performance counters for a particular service, i.e. Server Service (lanmanserver) or a particular SQL server instance (when there are multiple SQL instances running on the same server) , I will not be able to do so using the default performance collection module “System.Performance.OptimizedDataProvider” because server service runs under the generic service host svchost.exe. Typically, there are many instances of svchost.exe running for various services:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image31.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb31.png" alt="image" width="580" height="756" border="0" /></a></p>
<p>According to above screen capture, there are 10 instances of svchost.exe running on my computer. And when selecting performance counter in SCOM consoles, there are 10 instances of svchost:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image32.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb32.png" alt="image" width="537" height="428" border="0" /></a></p>
<p>It’s the same if I simply run perfmon on the computer: there are 10 instances of svchost:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image33.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb33.png" alt="image" width="580" height="426" border="0" /></a></p>
<p>There’s actually a blog article on TechNet explaining this issue with perfmon: <a href="http://blogs.technet.com/b/askperf/archive/2010/03/30/perfmon-identifying-processes-by-pid-instead-of-instance.aspx">Perfmon: Identifying processes by PID instead of instance</a></p>
<p>So, there is a workaround for perfmon, but it doesn’t really help me with my performance collection rule in SCOM.</p>
<p>To overcome this issue, I had to create some customized modules to collect the counters that I’m interested in via WMI. I’ll now explain what I’ve done to achieve the goal.</p>
<p>1. I firstly created a probe action module to run a vbscript to collect ALL the counters I’m interested in via WMI. In the script:</p>
<ol>
<li>takes the service name and computer name from the input parameter, get the PID for the service from <strong>win32_service</strong> class (note, I had to pass computer name to the script so it can connect to remote computer’s WMI namespace, this is required for agentless monitoring)</li>
<li>retrieve the values of the performance counters from <strong>Win32_PerfFormattedData_PerfProc_Process</strong> class using query <strong>&#8220;Select * from Win32_PerfFormattedData_PerfProc_Process Where IDProcess = ProcessID&#8221;</strong> (ProcessID was retrieved from step 1)</li>
<li>For each performance counter, create a property bag and add the property bag to MOM.ScriptAPI object</li>
<li>Return all property bags.</li>
</ol>
<p>2. Create a Data Source module which contains 3 modules and the modules are executed on the following order:</p>
<ol>
<li>System.SimpleScheduler (runs according to a schedule)</li>
<li>Probe module created from step 1 (retrieve performance counters and return then via property bag)</li>
<li>System.Performance.DataGenericMapper (Map the property bag values to performance data)</li>
</ol>
<p>Now that I’ve created all the required modules, I can then create a SINGLE rule to collect all different counters that I defined in the probe action module. To do so:</p>
<p>1. In Authoring console, create a Custom Rule:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image34.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb34.png" alt="image" width="311" height="236" border="0" /></a></p>
<p>2. Give the rule a name and choose the target:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image35.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb35.png" alt="image" width="580" height="578" border="0" /></a></p>
<p>3. Add the data source module I previously created and configure the variables (service name is the actual service name, <span style="color: #ff0000;"><strong>NOT</strong></span> service display name):</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image36.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb36.png" alt="image" width="580" height="534" border="0" /></a></p>
<p><strong><span style="color: #ff0000; font-size: medium;">Note:</span></strong> The <strong>Computername</strong> variable from above example is “$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$”, this is correct because I’m targeting the rule to Windows Computer. You will have to change it if you are targeting other classes. The best way is to use the prompt and choose the host’s principal name. Below is an example if I target the rule to Windows Operating System:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image37.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb37.png" alt="image" width="580" height="525" border="0" /></a></p>
<p>4. Add 2 Actions module (don’t need to configure them):</p>
<ol>
<li>Microsoft.SystemCenter.CollectionPerformanceData (WriteToDB)</li>
<li>Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData (WriteToDW)</li>
</ol>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image38.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb38.png" alt="image" width="580" height="455" border="0" /></a></p>
<p><strong><span style="color: #ff0000; font-size: medium;">Note:</span></strong> The 2nd action module WriteToDW is from Microsoft.SystemCenter.DataWarehouse.Library. you will have to add this library as a reference of your management pack.</p>
<p>Now, the rule is created, you can create a performance view for the rule and make sure it is collecting data:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image39.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb39.png" alt="image" width="580" height="479" border="0" /></a></p>
<p>Below is the VBScript I’ve used in probe action module:</p>
<pre class="brush: vb; title: ; notranslate">
'=========================================================================
' AUTHOR:             Tao Yang
' Script Name:        ProcessPerfMonData.vbs
' DATE:               23/01/2012
' Version:            1.0
' COMMENT:            Script to collect perfmon data for specific service
'=========================================================================
Option Explicit
SetLocale(&quot;en-us&quot;)
Dim ServiceName, objWMIService,colService, objService, ComputerName
Dim ProcessID, ProcessName, colProcess, objProcess, colPerfData, objPerfData
Dim ElapsedTime, PercentProcessorTime, PercentUserTime, ThreadCount, PageFaultsPersec, IOReadBytesPersec, IOWriteBytesPersec
Dim oAPI, oBag, oInst
ServiceName = WScript.Arguments.Item(0)
ComputerName = Wscript.Arguments.Item(1)
Set oAPI = CreateObject(&quot;MOM.ScriptAPI&quot;)

Set objWMIService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; &amp; ComputerName &amp;&quot;\root\cimv2&quot;)
Set colService = objWMIService.ExecQuery(&quot;Select * from Win32_Service Where Name = '&quot; + ServiceName + &quot;'&quot;)

For Each objService in colService
ProcessID = objService.ProcessID
Next

If ProcessID &lt;&gt; 0 THEN
Set colProcess = objWMIService.ExecQuery(&quot;Select * from Win32_Process Where ProcessID = &quot; &amp; ProcessID)
For Each objProcess in colProcess
ProcessName = objProcess.Name
Next
Set colPerfData = objWMIService.ExecQuery(&quot;Select * from Win32_PerfFormattedData_PerfProc_Process Where IDProcess = &quot; &amp; ProcessID)
For Each objPerfData in colPerfData
ElapsedTime = objPerfData.ElapsedTime
PercentProcessorTime = objPerfData.PercentProcessorTime
PercentUserTime = objPerfData.PercentUserTime
ThreadCount = objPerfData.ThreadCount
PageFaultsPersec = objPerfData.PageFaultsPersec
IOReadBytesPersec = objPerfData.IOReadBytesPersec
IOWriteBytesPersec = objPerfData.IOWriteBytesPersec
Next
'Elapsed Time
Set oBag = oAPI.CreatePropertyBag()
oBag.AddValue &quot;Object&quot;, &quot;Process&quot;
oBag.AddValue &quot;Instance&quot;, ServiceName
oBag.AddValue &quot;Counter&quot;, &quot;Elapsed Time&quot;
oBag.AddValue &quot;Value&quot;, ElapsedTime
oAPI.AddItem(oBag)

'Percent Processor Time
Set oBag = oAPI.CreatePropertyBag()
oBag.AddValue &quot;Object&quot;, &quot;Process&quot;
oBag.AddValue &quot;Instance&quot;, ServiceName
oBag.AddValue &quot;Counter&quot;, &quot;% Processor Time&quot;
oBag.AddValue &quot;Value&quot;, PercentProcessorTime
oAPI.AddItem(oBag)

'Percent User Time
Set oBag = oAPI.CreatePropertyBag()
oBag.AddValue &quot;Object&quot;, &quot;Process&quot;
oBag.AddValue &quot;Instance&quot;, ServiceName
oBag.AddValue &quot;Counter&quot;, &quot;% User Time&quot;
oBag.AddValue &quot;Value&quot;, PercentUserTime
oAPI.AddItem(oBag)

'Thread Count
Set oBag = oAPI.CreatePropertyBag()
oBag.AddValue &quot;Object&quot;, &quot;Process&quot;
oBag.AddValue &quot;Instance&quot;, ServiceName
oBag.AddValue &quot;Counter&quot;, &quot;Thread Count&quot;
oBag.AddValue &quot;Value&quot;, ThreadCount
oAPI.AddItem(oBag)

'Page Faults/Sec
Set oBag = oAPI.CreatePropertyBag()
oBag.AddValue &quot;Object&quot;, &quot;Process&quot;
oBag.AddValue &quot;Instance&quot;, ServiceName
oBag.AddValue &quot;Counter&quot;, &quot;Page Faults/sec&quot;
oBag.AddValue &quot;Value&quot;, PageFaultsPersec
oAPI.AddItem(oBag)

'IO Read Bytes/sec
Set oBag = oAPI.CreatePropertyBag()
oBag.AddValue &quot;Object&quot;, &quot;Process&quot;
oBag.AddValue &quot;Instance&quot;, ServiceName
oBag.AddValue &quot;Counter&quot;, &quot;IO Read Bytes/sec&quot;
oBag.AddValue &quot;Value&quot;, IOReadBytesPersec
oAPI.AddItem(oBag)

'IO Write Bytes/sec
Set oBag = oAPI.CreatePropertyBag()
oBag.AddValue &quot;Object&quot;, &quot;Process&quot;
oBag.AddValue &quot;Instance&quot;, ServiceName
oBag.AddValue &quot;Counter&quot;, &quot;IO Write Bytes/sec&quot;
oBag.AddValue &quot;Value&quot;, IOWriteBytesPersec
oAPI.AddItem(oBag)
ELSE
'Return an empty property bag
Set oBag = oAPI.CreatePropertyBag()
oAPI.AddItem(oBag)
END IF
oAPI.ReturnItems
</pre>
<p>As you can see, I’m collecting the following 7 counters in the script:</p>
<ol>
<li>Elapsed Time</li>
<li>% Processor Time</li>
<li>% User Time</li>
<li>Thread Count</li>
<li>Page Faults/sec</li>
<li>IO Read Bytes/sec</li>
<li>IO Write Bytes/sec</li>
</ol>
<p>You will need to modify the script if you are collecting different counters. for details of the counters you can collect, please refer to Win32_PerfFormattedData_PerfProc_Process class documentation here at MSDN: <a title="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394277(v=vs.85).aspx" href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394277(v=vs.85).aspx">http://msdn.microsoft.com/en-us/library/windows/desktop/aa394277(v=vs.85).aspx</a></p>
<p>I’ve attached the script and the sample unsealed management pack at the bottom of this article. You can modify or recreate your own based on the samples. don’t forget to seal the management pack if you want to use the modules in other MPs.</p>
<p>VBScript: <a href="http://blog.tyang.org/wp-content/uploads/2012/01/ProcessPerfMonData.txt">ProcessPerfMonData.txt</a></p>
<p>Unsealed MP: <a href="http://blog.tyang.org/wp-content/uploads/2012/01/TYANG.Custom.Performance.Monitoring.zip">TYANG.Custom.Performance.Monitoring.xml</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2012/01/27/scom-process-performance-collection-rule-for-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SCOM: Powershell Property Bag Trigger Only Probe VS Windows Script Property Bag Probe</title>
		<link>http://blog.tyang.org/2012/01/27/scom-powershell-property-bag-trigger-only-probe-vs-windows-script-property-bag-probe/</link>
		<comments>http://blog.tyang.org/2012/01/27/scom-powershell-property-bag-trigger-only-probe-vs-windows-script-property-bag-probe/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 23:44:56 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCOM]]></category>
		<category><![CDATA[MP Authoring]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=867</guid>
		<description><![CDATA[When writing a Probe Action Module to run a trigger only PowerShell script and return property bags, Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe module can be used. However, there is no trigger only probe module if you want to run VBScript. Below are 2 examples how to create trigger only probe modules for both PowerShell and VBScript: 1. PowerShell Member [...]]]></description>
			<content:encoded><![CDATA[<p>When writing a Probe Action Module to run a trigger only PowerShell script and return property bags, <strong>Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe</strong> module can be used. However, there is no trigger only probe module if you want to run VBScript.</p>
<p>Below are 2 examples how to create trigger only probe modules for both PowerShell and VBScript:</p>
<h2><span style="font-weight: bold;">1. PowerShell</span></h2>
<h3>Member Modules:</h3>
<p><strong>Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe</strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image27.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb27.png" alt="image" width="580" height="455" border="0" /></a></p>
<h3>Data Types:</h3>
<p>Input: Trigger Only</p>
<p>Output: System.PropertyBag Data</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image28.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb28.png" alt="image" width="580" height="455" border="0" /></a></p>
<h2><span style="font-weight: bold;">2. VBScript:</span></h2>
<h3>Member Modules:</h3>
<p><strong>System.PassThroughProbe</strong></p>
<p><strong>Microsoft.Windows.ScriptPropertyBagProbe</strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image29.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb29.png" alt="image" width="580" height="455" border="0" /></a></p>
<h3>Data Type:</h3>
<p>Input: Trigger Only</p>
<p>Output: System.PropertyBag Data</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image30.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb30.png" alt="image" width="580" height="450" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2012/01/27/scom-powershell-property-bag-trigger-only-probe-vs-windows-script-property-bag-probe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run Batch File for SCOM Monitor’s Recovery Task</title>
		<link>http://blog.tyang.org/2012/01/25/run-batch-file-for-scom-monitors-recovery-task/</link>
		<comments>http://blog.tyang.org/2012/01/25/run-batch-file-for-scom-monitors-recovery-task/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 00:59:36 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCOM]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=856</guid>
		<description><![CDATA[This is how I configured recovery task to run a batch file: Actions Module Type: System.CommandExecuter Module Configuration Application Name: C:\Windows\System32\cmd.exe Working Directory: C:\Windows\System32 CommandLine: /c &#60;Path to Batch file&#62; (i.e. /c C:\Apps\DelFile.bat) TimeoutSeconds: &#60;i.e. 60&#62; RequiredOutput: true &#160; &#160;]]></description>
			<content:encoded><![CDATA[<p>This is how I configured recovery task to run a batch file:</p>
<p>Actions Module Type: <strong>System.CommandExecuter</strong></p>
<p>Module Configuration</p>
<p>Application Name: C:\Windows\System32\cmd.exe</p>
<p>Working Directory: C:\Windows\System32</p>
<p>CommandLine: /c &lt;Path to Batch file&gt; (i.e. /c C:\Apps\DelFile.bat)</p>
<p>TimeoutSeconds: &lt;i.e. 60&gt;</p>
<p>RequiredOutput: true</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2012/01/25/run-batch-file-for-scom-monitors-recovery-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Script: Convert To Local Time From UTC</title>
		<link>http://blog.tyang.org/2012/01/11/powershell-script-convert-to-local-time-from-utc/</link>
		<comments>http://blog.tyang.org/2012/01/11/powershell-script-convert-to-local-time-from-utc/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 07:20:59 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=850</guid>
		<description><![CDATA[I wrote this function in the script from my previous post “SCOM MP Authoring Example: Generate alerts based on entries from SQL Database (Part 2 of 2)”. It comes handy sometimes so I thought I’ll blog it separately as well. In PowerShell Datetime object, there is a ToUniversalTime() method that converts local time to UTC [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this function in the script from my previous post “<a href="http://blog.tyang.org/2012/01/05/scom-mp-authoring-example-generate-alerts-based-on-entries-from-sql-database-part-2-of-2/">SCOM MP Authoring Example: Generate alerts based on entries from SQL Database (Part 2 of 2)</a>”. It comes handy sometimes so I thought I’ll blog it separately as well.</p>
<p>In PowerShell Datetime object, there is a ToUniversalTime() method that converts local time to UTC time.</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image25.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb25.png" alt="image" width="532" height="303" border="0" /></a></p>
<p>However, there isn’t a native way to convert FROM UTC To local time. So I wrote this function:</p>
<pre class="brush: powershell; title: ; notranslate">
Function Get-LocalTime($UTCTime)
{
$strCurrentTimeZone = (Get-WmiObject win32_timezone).StandardName
$TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($strCurrentTimeZone)
$LocalTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)
Return $LocalTime
}
</pre>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image26.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb26.png" alt="image" width="580" height="263" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2012/01/11/powershell-script-convert-to-local-time-from-utc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SCOM MP Authoring Example: Generate alerts based on entries from SQL Database (Part 2 of 2)</title>
		<link>http://blog.tyang.org/2012/01/05/scom-mp-authoring-example-generate-alerts-based-on-entries-from-sql-database-part-2-of-2/</link>
		<comments>http://blog.tyang.org/2012/01/05/scom-mp-authoring-example-generate-alerts-based-on-entries-from-sql-database-part-2-of-2/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 08:41:11 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCOM]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[MP Authoring]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=833</guid>
		<description><![CDATA[This is the 2nd part of the 2-part series.  Part 1 can be found here. In Part 2, I’ll cover the steps involved to create each module type and the rule in this article. all these objects will be created in SCOM 2007 R2 Authoring Console. You can create a new management pack for this [...]]]></description>
			<content:encoded><![CDATA[<p>This is the 2nd part of the 2-part series.  Part 1 can be found <a title="SCOM MP Authoring Example: Generate alerts based on entries from SQL Database (Part 1 of 2)" href="http://blog.tyang.org/2012/01/04/scom-mp-authoring-example-generate-alerts-based-on-entries-from-sql-database-part-1-of-2/">here</a>.</p>
<p>In Part 2, I’ll cover the steps involved to create each module type and the rule in this article. all these objects will be created in SCOM 2007 R2 Authoring Console. You can create a new management pack for this or use an existing one.</p>
<p>Firstly, we will need create the probe action and data source modules:</p>
<p><strong><span style="font-size: medium;">Probe Action Module:</span></strong></p>
<p>1. Under Type Library pane, go to “Probe Actions” under Module Types and click New—&gt;”Composite Probe Action…”</p>
<p>2. Give it a unique identifier such as “Your.Management.pack.Prefix.Database.Catcher.Probe.Action”</p>
<p>3. in general tab, give it a name:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb1.png" alt="image" width="466" height="462" border="0" /></a></p>
<p>4. Under Member Modules, add <strong>“Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe</strong>” and give it a Module ID of “PSScript”</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image2.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb2.png" alt="image" width="483" height="481" border="0" /></a></p>
<p>5. Click on Edit</p>
<p>6. Enter the ScriptName and TImeoutSeconds. Then Edit again in the Configuration tab of the probe action module</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image3.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb3.png" alt="image" width="471" height="475" border="0" /></a></p>
<p>6. When the text editor is launched, Enter the powershell script in between &lt;ScriptBody&gt; and &lt;/ScriptBody&gt; tags</p>
<p>7. Below is the script I used in my management pack. please edit it to suit your needs:</p>
<pre class="brush: powershell; title: ; notranslate">
#-----------------------------------
#Alarms capture via AuditDB
#Name:        AuditDBAlarmCatcher.PS1
#Param 0:    SQL Database Instance Name
#Param 2:    Database name
#Param 2:    The inteval in seconds
#Author:    Tao Yang
#Date:        07/12/2011
#-----------------------------------

param([string]$SQLInstance,[String]$Database,[Int]$Interval)
$EVENT_TYPE_ERROR = 1
$EVENT_TYPE_WARNING = 2
$EVENT_TYPE_INFORMATION = 4

Function Get-LocalTime($UTCTime)
{
$strCurrentTimeZone = (Get-WmiObject win32_timezone).StandardName
$TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($strCurrentTimeZone)
$LocalTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)
Return $LocalTime
}

$oAPI = New-Object -ComObject &quot;MOM.ScriptAPI&quot;
$oBag = $oAPI.CreatePropertyBag()
$strServer = &quot;.\$SQLInstance&quot;

$ADOCon = New-Object -ComObject &quot;ADODB.Connection&quot;
$oResults = New-Object -ComObject &quot;ADODB.Recordset&quot;
$adOpenStatic = 3
$adLockOptimistic = 3
$ADOCon.Provider = &quot;sqloledb&quot;
$ADOCon.ConnectionTimeout = 60
$nowInUTC = (Get-Date).ToUniversalTime()
$StartTime = $nowInUTC.AddSeconds(-$Interval)
$conString = &quot;Server=$strServer;Database=$Database;Integrated Security=SSPI&quot;
$strQuery = &quot;Select * from V_Audit Where EventTypeCaption LIKE 'Alarm triggered' AND EventDate &gt;= '$StartTime'&quot;
$ADOCon.Open($conString)
$oResults.Open($strQuery, $ADOCon, $adOpenStatic, $adLockOptimistic)
$oBag.AddValue('Interval', $Interval)
If (!$oResults.EOF)
{
If (!([appdomain]::currentdomain.getassemblies() | Where-Object {$_.FullName -ieq &quot;system.core&quot;}))
{
Try {
Write-Host &quot;Loading .NET DLL into Powershell...&quot; -ForegroundColor Green
[Void][System.Reflection.Assembly]::LoadWithPartialName(&quot;System.Core&quot;)
} Catch {
#We cannot use Write-Error cmdlet here because $ErrorActionPreference is set to &quot;SilentlyContinue&quot; so it won't display on the screen.
Write-Host &quot;Unable to load .NET Framework into Powershell, please make sure it is installed!&quot; -foregroundColor Red
Exit
}
}
$oBag.AddValue('GenerateAlert', 'True')
$arrLogEntries = @()
$oResults.MoveFirst()
Do {
$EventDate = $oResults.Fields.Item(&quot;EventDate&quot;).Value
$EventDate = Get-LocalTime $EventDate
$Description = $oResults.Fields.Item(&quot;Description&quot;).Value
$arrLogEntries += &quot;- $EventDate`: $Description&quot;
$oResults.MoveNext()
} until ($oResults.EOF)
$LogDetail = [System.String]::Join(&quot;&amp;#13;&quot;, $arrLogEntries)
$intEntryCount = $arrLogEntries.count
Remove-Variable arrLogEntries
} else {
$oBag.AddValue('GenerateAlert', 'False')
$intEntryCount = 0
}
$oResults.Close()
$ADOCon.Close()

$oBag.AddValue('LogEntry', $LogDetail)
$oBag.AddValue('LogEntryCount', $intEntryCount)
$oBag
</pre>
<p>8. Enter below sections after &lt;/ScriptBody&gt; and before &lt;TimeoutSeoncds&gt;:</p>
<p><strong>&lt;Parameters&gt;<br />
&lt;Parameter&gt;<br />
&lt;Name&gt;SQLInstance&lt;/Name&gt;<br />
&lt;Value&gt;$Config/SQLInstance$&lt;/Value&gt;<br />
&lt;/Parameter&gt;<br />
&lt;Parameter&gt;<br />
&lt;Name&gt;Database&lt;/Name&gt;<br />
&lt;Value&gt;$Config/Database$&lt;/Value&gt;<br />
&lt;/Parameter&gt;<br />
&lt;Parameter&gt;<br />
&lt;Name&gt;Interval&lt;/Name&gt;<br />
&lt;Value&gt;$Config/Interval$&lt;/Value&gt;<br />
&lt;/Parameter&gt;<br />
&lt;/Parameters&gt;</strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image4.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb4.png" alt="image" width="501" height="387" border="0" /></a></p>
<p>9. Click Save in the text editor and close it. you should now see what you’ve entered in the configuration tab of the probe action module:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image5.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb5.png" alt="image" width="580" height="582" border="0" /></a></p>
<p>10. Click OK to exit the configuration tab. Under Configuration Schema tab, add 3 parameters (in same order) as shown below:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image6.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb6.png" alt="image" width="579" height="577" border="0" /></a></p>
<p>11. Under Data Types, make sure the input and output data is set as below (should be default anyway):</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image7.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb7.png" alt="image" width="580" height="575" border="0" /></a></p>
<p>12. Under Options, I left Accessibility to “Internal”, but if you are going to use this module outside of this management pack, set it to public.</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image8.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb8.png" alt="image" width="580" height="256" border="0" /></a></p>
<p>13. Now click OK to exit the probe module window. the probe action module is now created. Now it’s a good time to save the management pack.</p>
<p><span style="font-size: medium;"><strong>Data Sources Module:</strong></span></p>
<p>1. Under Type Library pane, go to “Data Sources” under Module Types and click New—&gt;”Composite Data Source…”</p>
<p>2. Give it a unique identifier such as “Your.Management.pack.Prefix.Database.Catcher.DataSource”</p>
<p>3. Open the data source module you’ve just created and give it a display name under “General” tab:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image9.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb9.png" alt="image" width="514" height="508" border="0" /></a></p>
<p>4. Add 2 member modules:</p>
<table width="650" border="1" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="158">
<p align="center"><strong>Module ID</strong></p>
</td>
<td valign="top" width="155">
<p align="center"><strong>Role</strong></p>
</td>
<td valign="top" width="232">
<p align="center"><strong>Type</strong></p>
</td>
<td valign="top" width="103">
<p align="center"><strong>Next Module</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="157">Schedule</td>
<td valign="top" width="155">Data Source</td>
<td valign="top" width="232"><strong>System.SimpleScheduler</strong></td>
<td valign="top" width="103">Probe</td>
</tr>
<tr>
<td valign="top" width="158">Probe</td>
<td valign="top" width="154">Probe Action</td>
<td valign="top" width="232"><strong>Probe Action module you’ve just created</strong></td>
<td valign="top" width="103">Module Output</td>
</tr>
</tbody>
</table>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image10.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb10.png" alt="image" width="580" height="299" border="0" /></a></p>
<p>5. Edit the SimpleScheduler module, for the IntervalSeconds value, click on “promote…”. this will set it to “$Config/IntervalSeconds$”. and leave SyncTime to blank:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image11.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb11.png" alt="image" width="580" height="326" border="0" /></a></p>
<p>6. Edit the probe action module, use promote to set values for all 3 parameters:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image12.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb12.png" alt="image" width="580" height="587" border="0" /></a></p>
<p>7. Configure “Configuration Schema” tab as below (again, make sure these parameters are in the right order&#8221;):</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image13.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb13.png" alt="image" width="580" height="575" border="0" /></a></p>
<p>8. Configure Overridable Parameters as below:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image14.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb14.png" alt="image" width="580" height="570" border="0" /></a></p>
<p>9. Make sure output data type is set to <strong>System.PropertyBagData</strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image15.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb15.png" alt="image" width="580" height="194" border="0" /></a></p>
<p>10. Set accessibility to “public” if you are going to access this module from other management packs.</p>
<p>Now the data source module is complete. We are going to create the rule next.</p>
<p><span style="font-size: medium;"><strong>Rule:</strong></span></p>
<p>1. Under Health Model pane, go to “Rules” and click New—&gt;”Custom Rule…”</p>
<p>2. Give it a unique identifier such as “Your.Management.pack.Prefix.Database.Catcher.Rule”</p>
<p>3. Give the rule a display name  and select the target class where you want to run the rule under general tab</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image16.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb16.png" alt="image" width="580" height="573" border="0" /></a></p>
<p>4. In Modules tab, create a data source module with the type of the data source module type you’ve created previously. give it a module ID of DataSource</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image17.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb17.png" alt="image" width="580" height="251" border="0" /></a></p>
<p>5. Edit the data source module configuration, enter the values for all 3 parameters: <strong>SQLInstance</strong>, <strong>Database</strong> and <strong>IntervalSeconds</strong>:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image18.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb18.png" alt="image" width="580" height="306" border="0" /></a></p>
<p>According to above example, this rule will connect to the database “AuditDB” in the particular SQL instance that you specified and will run in every 5 minutes (300 seconds)</p>
<p>6. Now, create a condition detect module with type: <strong>System.ExpressionFilter</strong> and Module ID: <strong>Filter_AlertCondition</strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image19.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb19.png" alt="image" width="576" height="576" border="0" /></a></p>
<p>7. Edit the condition detection module, under configuration tab, click on Configure… button.</p>
<p>8. Enter the expression as below:</p>
<p>Parameter Name: <strong>Property[@Name='GenerateAlert']</strong></p>
<p>Operator: <strong>Equals</strong></p>
<p>Value: <strong>True</strong></p>
<p>Click OK to save.</p>
<p>It looks like this when it’s done:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image20.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb20.png" alt="image" width="554" height="559" border="0" /></a></p>
<p>9. Create an Action module. Type: <strong>System.Health.GenerateAlert</strong>. ModuleID: <strong>Alert</strong>.</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image21.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb21.png" alt="image" width="580" height="572" border="0" /></a></p>
<p>10. Click Edit for the Action module then click Edit again under Configuration tab to edit the XML.</p>
<p>11. Add below section in the XML before &lt;/Configuration&gt; tag:</p>
<p><strong>&lt;AlertParameters&gt;<br />
&lt;AlertParameter1&gt;$Target/Property[Type="System!System.Entity"]/DisplayName$&lt;/AlertParameter1&gt;<br />
&lt;AlertParameter2&gt;$Data/Property[@Name='Interval']$&lt;/AlertParameter2&gt;<br />
&lt;AlertParameter3&gt;$Data/Property[@Name='LogEntryCount']$&lt;/AlertParameter3&gt;<br />
&lt;AlertParameter4&gt;$Data/Property[@Name='LogEntry']$&lt;/AlertParameter4&gt;<br />
&lt;/AlertParameters&gt;</strong><br />
<a href="http://blog.tyang.org/wp-content/uploads/2012/01/image22.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb22.png" alt="image" width="580" height="155" border="0" /></a></p>
<p>12. save the XML and exit the text editor. then click on Configure to configure the alert. you may use the parameters from previous step to form the alert description.</p>
<p>13.Edit the Production knowledge of this rule if you like. it will also appear with the alert.</p>
<p>Now we are done. You can save this unsealed management pack or seal it using authoring console. please make sure you test it before import it into your production environment.</p>
<p>Below is a sample alert from my test environment:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image23.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb23.png" alt="image" width="580" height="438" border="0" /></a></p>
<p><strong>Few notes:</strong></p>
<ol>
<li>The database that I had to work with was a SQL Express DB. I found this free tool extremely useful since I can’t use SQL management studio to connect to SQL Express databases:  <a href="http://www.dbsoftlab.com/database-editors/database-browser/overview.html">Database Browser</a>. The database table screen capture from Part 1 of this series was from this tool.</li>
<li>When testing the PowerShell Script, I needed to run the script under Local Systems as my account did not have access to the database. Since in my script, I connected to the database using integrated security, I had to make sure I run the script under the account which is going to be used to run the rule (in my case, Local Systems), I had to use <a href="http://technet.microsoft.com/en-us/sysinternals/bb897553">PSExec</a> from Sysinternals to launch Powershell as it allows me to run executables under Local System.</li>
<li>Originally I used a multi-line string variable in PowerShell script to store records returned from SQL query (one record per line). It didn’t work after added the script to the management pack. I figured out i can use the special HTML character for carriage return inside the string variable in Powershell. So the line looks like this:</li>
</ol>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image24.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb24.png" alt="image" width="580" height="26" border="0" /></a></p>
<p>My sample PowerShell script can be downloaded from <a href="http://blog.tyang.org/wp-content/uploads/2012/01/AuditDBAlarmCatcher.txt">HERE</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2012/01/05/scom-mp-authoring-example-generate-alerts-based-on-entries-from-sql-database-part-2-of-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SCOM MP Authoring Example: Generate alerts based on entries from SQL Database (Part 1 of 2)</title>
		<link>http://blog.tyang.org/2012/01/04/scom-mp-authoring-example-generate-alerts-based-on-entries-from-sql-database-part-1-of-2/</link>
		<comments>http://blog.tyang.org/2012/01/04/scom-mp-authoring-example-generate-alerts-based-on-entries-from-sql-database-part-1-of-2/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 09:12:02 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCOM]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[MP Authoring]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=779</guid>
		<description><![CDATA[This is probably going to be a bit too long for one single blog post. I’ll separate this topic into 2 articles: Part 1 includes the background and overview of the rule and it’s workflow Part 2 documents all the steps to create all the module types and the rule itself. This article is the [...]]]></description>
			<content:encoded><![CDATA[<p>This is probably going to be a bit too long for one single blog post. I’ll separate this topic into <strong>2 articles</strong>:</p>
<ol>
<li>Part 1 includes the background and overview of the rule and it’s workflow</li>
<li><a href="http://blog.tyang.org/2012/01/05/scom-mp-authoring-example-generate-alerts-based-on-entries-from-sql-database-part-2-of-2/">Part 2</a> documents all the steps to create all the module types and the rule itself.</li>
</ol>
<p><strong>This article is the first part of the 2-part series.</strong></p>
<p>Recently, I’ve been writing a SCOM management pack for a new application that my employer is implementing. This application logs any application related alarms into a SQL express database. One of the requirement for the MP is to catch these alarms from the database and generate alerts based on these alarms.</p>
<p>In the database, I’m interested in any records that has the value of “Alarm triggered” in “EventTypeCaption” column.</p>
<p>The the record is added to the database, the application also adds the time stamp in UTC to the “EventDate” field.</p>
<p>Below is a snapshot of a subset of the database. I’ve highlighted the records that I’m interested in:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/image.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2012/01/image_thumb.png" alt="image" width="580" height="419" border="0" /></a></p>
<p>To achieve this goal, I’ve written some custom modules and created a rule using these modules.</p>
<p><strong><span style="font-size: medium;">Rule overview:</span></strong></p>
<p>As usual, the rule contains 3 modules:</p>
<ol>
<li>Data Source</li>
<li>Condition Detection</li>
<li>Actions</li>
</ol>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/Rule.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Rule" src="http://blog.tyang.org/wp-content/uploads/2012/01/Rule_thumb.jpg" alt="Rule" width="304" height="441" border="0" /></a></p>
<p>Below is the flow chat for the entire workflow:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2012/01/workflow.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="workflow" src="http://blog.tyang.org/wp-content/uploads/2012/01/workflow_thumb.jpg" alt="workflow" width="397" height="779" border="0" /></a></p>
<p>To explain the workflow in details:</p>
<ol>
<li>The workflow takes 3 inputs:</li>
<ol>
<li>IntervalSeconds – how frequent does the rule run</li>
<li>SQLInstance – Name of the SQL instance</li>
<li>Database – Name of the database</li>
</ol>
<li>The data source member module system.simple.scheduler runs according to the intervalseconds</li>
<li>The Probe Action member module (a PowerShell script) takes all 3 inputs:</li>
<ol>
<li>connect to the database in the SQL instance as specified from the input</li>
<li>calculate the earliest time (current time minus intervalseconds from the input then convert to UTC). store the earliest time in a datetime variable $starttime</li>
<li>Build the SQL query: <strong>&#8220;Select * from &lt;table name&gt; Where EventTypeCaption LIKE &#8216;Alarm triggered&#8217; AND EventDate &gt;= &#8216;$StartTime&#8217;&#8221;</strong></li>
<li>Execute the SQL query.</li>
<li>If returned any data:</li>
<ol>
<li>Property Bag value “GenerateAlert” = True</li>
<li>For each record, convert the EventDate from UTC time to local time.</li>
<li>combine all records from the record set to a multi line string that include converted event date and event description. return this string as Property Bag value “LogEntry”</li>
<li>return Property Bag Value “LogEntryCount”</li>
</ol>
</ol>
<li>Condition Detection module detects Property Bag value “GenerateAlert” = True</li>
<li>If passed Condition Detection Module, the Write Action module generates alert with LogEntry and LogEntryCount in alert description field.</li>
</ol>
<p><strong><span style="color: #ff0000; font-size: medium;">Note:</span></strong> I’m using <strong>PowerShellPropertyTriggerOnlyProbe</strong> rather than VBscript because I found it’s easier to convert UTC and local time back and forth as I can simply use .NET class System.TimeZoneInfo and powershell datetime object ToUTC() method to do the conversion. if we are to use VBScript, there is no equivalent trigger only probe for VBScript. I’ll try to cover this in a separate blog post.</p>
<p><strong>What’s Next?</strong></p>
<p>I’ll go through how to create each module types and the rule itself in part 2 of this series.</p>
<p><strong>To be continued…</strong></p>
<p><a href="http://blog.tyang.org/2012/01/05/scom-mp-authoring-example-generate-alerts-based-on-entries-from-sql-database-part-2-of-2/">Part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2012/01/04/scom-mp-authoring-example-generate-alerts-based-on-entries-from-sql-database-part-1-of-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SCOM: Using PowerShell to update SMTP server address in SMTP notification Channels</title>
		<link>http://blog.tyang.org/2011/12/10/scom-using-powershell-to-update-smtp-server-address-in-smtp-notification-channels/</link>
		<comments>http://blog.tyang.org/2011/12/10/scom-using-powershell-to-update-smtp-server-address-in-smtp-notification-channels/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 10:37:10 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCOM]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=765</guid>
		<description><![CDATA[I&#8217;ve been asked a question on how to bulk update SMTP server addresses in SMTP notification channels using PowerShell. Here’s the script to run in OpsMgr Command Shell:]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been asked a question on how to bulk update SMTP server addresses in SMTP notification channels using PowerShell.</p>
<p>Here’s the script to run in OpsMgr Command Shell:</p>
<pre class="brush: powershell; title: ; notranslate">
$newSMTP = &lt;name of your new SMTP server&gt;
$SMTPChannels = Get-NotificationAction |Where-Object {$_.Name –imatch “smtp”}
Foreach ($item in $SMTPChannels)
{
$item.Endpoint.PrimaryServer.Address = $newSMTP
$item.Endpoint.update()
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2011/12/10/scom-using-powershell-to-update-smtp-server-address-in-smtp-notification-channels/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run 64-bit PowerShell via SCCM 2007 Advertisement</title>
		<link>http://blog.tyang.org/2011/11/08/run-64-bit-powershell-via-sccm-2007-advertisement/</link>
		<comments>http://blog.tyang.org/2011/11/08/run-64-bit-powershell-via-sccm-2007-advertisement/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 10:16:53 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SCCM]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=762</guid>
		<description><![CDATA[A colleague came across a problem today. He could run a SCDPM PowerShell script from PowerShell console successfully but could not run it when packaged it in SCCM. We soon found out it’s because SCCM 2007 is a 32-bit app and DPM PowerShell snapin is only available for 64-bit PowerShell because we could not run [...]]]></description>
			<content:encoded><![CDATA[<p>A colleague came across a problem today. He could run a SCDPM PowerShell script from PowerShell console successfully but could not run it when packaged it in SCCM.</p>
<p>We soon found out it’s because SCCM 2007 is a 32-bit app and DPM PowerShell snapin is only available for 64-bit PowerShell because we could not run the script from a 32-bit PowerShell console.</p>
<p>When a 32-bit application tries to access %WinDir%\system32, Windows redirects it to %WinDir%\SysWOW64. In order for the 32-bit app to access %WinDir%\System32 folder, we have to use <strong>%Windir%\sysnative</strong>.</p>
<p>So, we set the command line of the program in SCCM package to <strong>“%WinDir%\Sysnative\WindowsPowerShell\V1.0\Powershell.exe” –noprofile .\PowerShellScript.ps1</strong> as that’s where the 64-bit version of PowerShell is and the SCCM advertisement ran successfully on the client.</p>
<p>More reading regarding to file system redirection here: <a title="http://support.microsoft.com/kb/942589" href="http://support.microsoft.com/kb/942589">http://support.microsoft.com/kb/942589</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2011/11/08/run-64-bit-powershell-via-sccm-2007-advertisement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SCOM Management Pack: Detecting USB Storage Device Connect and Disconnect Events</title>
		<link>http://blog.tyang.org/2011/10/23/scom-management-pack-detecting-usb-storage-device-connect-and-disconnect-events/</link>
		<comments>http://blog.tyang.org/2011/10/23/scom-management-pack-detecting-usb-storage-device-connect-and-disconnect-events/#comments</comments>
		<pubDate>Sun, 23 Oct 2011 09:56:07 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCOM]]></category>
		<category><![CDATA[Management Pack]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=756</guid>
		<description><![CDATA[There was a requirement at work that people need to be notified when a USB storage device (USB key or portable USB hard disks) is connected or disconnected from SCOM monitored Windows computers. So I wrote a 2 very simple alert generating rules to detect USB Mass Storage Device creation and deletion WMI event. I [...]]]></description>
			<content:encoded><![CDATA[<p>There was a requirement at work that people need to be notified when a USB storage device (USB key or portable USB hard disks) is connected or disconnected from SCOM monitored Windows computers.</p>
<p>So I wrote a 2 very simple alert generating rules to detect USB Mass Storage Device creation and deletion WMI event. I set both rules to run every 60 seconds so within 60 seconds of the event, an Information alert is generated in SCOM:</p>
<p><strong>Alert for USB Storage Device Connection Event:</strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image15.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb15.png" alt="image" width="580" height="582" border="0" /></a></p>
<p><strong>Alert for USB Storage Device Removal Event:</strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image16.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb16.png" alt="image" width="580" height="496" border="0" /></a></p>
<p>I have also created a dynamic group called Virtual Windows Computers in the MP so I can disable both rules for virtual machines. This is how I defined the group:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image17.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb17.png" alt="image" width="580" height="256" border="0" /></a></p>
<p>Please note this Virtual Machine discovery only detects virtual machines running on Microsoft’s virtual host platform. If you open System Center Internal Library MP in MPViewer and check the Raw XML for discovery “<strong>Discover if Windows Computer is a Virtual Machine</strong>”, you’ll see it the WQL:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image18.png"><img style="border: 0px currentColor; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb18.png" alt="image" width="740" height="519" border="0" /></a></p>
<p>So if you have non-Microsoft virtual machines (i.e. VMware) in your environment and you want to disable these 2 rules for those virtual machines, you will need to modify my group or create your own group in my management pack.</p>
<p><strong>Download: <a href="http://blog.tyang.org/wp-content/uploads/2011/10/USB.Storage.Device.Detection.zip">USB Storage Device Detection Management Pack</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2011/10/23/scom-management-pack-detecting-usb-storage-device-connect-and-disconnect-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extend ConfigMgr Hardware Inventory to capture OpsMgr configurations</title>
		<link>http://blog.tyang.org/2011/10/12/extend-configmgr-hardware-inventory-to-capture-opsmgr-configurations/</link>
		<comments>http://blog.tyang.org/2011/10/12/extend-configmgr-hardware-inventory-to-capture-opsmgr-configurations/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 08:40:52 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCCM]]></category>
		<category><![CDATA[SCOM]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hardware Inventory]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=730</guid>
		<description><![CDATA[Download: MOF Extension for OpsMgr Configurations I’ve been wanting to do this for a while now and finally found some spare time for it. I want to be able to target OpsMgr (SCOM) agents and servers in ConfigMgr (SCCM) in a more granular way (i.e. all OpsMgr agents that are reporting to a OpsMgr Management [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Download</strong>: <a href="http://blog.tyang.org/wp-content/uploads/2011/10/OpsMgr-2007-MOF.zip">MOF Extension for OpsMgr Configurations</a></p>
<p>I’ve been wanting to do this for a while now and finally found some spare time for it. I want to be able to target OpsMgr (SCOM) agents and servers in ConfigMgr (SCCM) in a more granular way (i.e. all OpsMgr agents that are reporting to a OpsMgr Management Server, or all OpsMgr agents within a OpsMgr management group or All OpsMgr management servers)</p>
<p>Therefore, I created these extensions for <strong>configuration.mof</strong> and <strong>sms_def.mof</strong> so OpsMgr settings are captured as part of ConfigMgr client hardware inventory.</p>
<p>Once loaded in to ConfigMgr and after clients have retrieved new policy and performed hardware inventory, you will be able to see this in Resource Explorer:</p>
<p><strong>For OpsMgr Agents:</strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image13.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb13.png" alt="image" width="580" height="429" border="0" /></a></p>
<p><strong>For OpsMgr Servers:</strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image14.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb14.png" alt="image" width="580" height="407" border="0" /></a></p>
<p><strong>Note:</strong> As always, make sure backup both mof files before editing them. once saved, monitor dataldr.log to make sure they are successfully compiled.</p>
<p>Please refer to my <a href="http://blog.tyang.org/2011/10/09/clean-up-old-hardware-inventory-data/">previous blog </a>if you decide to remove this mof extention from your ConfigMgr environment.</p>
<p><strong>More Reading about ConfigMgr Hinv (Hardware Inventory):</strong></p>
<p><a href="http://technet.microsoft.com/en-us/library/bb632896.aspx">Technet: About MOF Files Used by Hardware Inventory</a></p>
<p><a href="http://blogs.technet.com/b/smsandmom/archive/2007/08/30/how-to-extend-your-hardware-inventory-using-the-sms-def-mof-file.aspx">Technet Blog: How to Extend Your Hardware Inventory Using the SMS_DEF.MOF File</a></p>
<p><strong>Collection Query Samples:</strong></p>
<p>All OpsMgr agents in Management Group TYANG:</p>
<pre class="brush: sql; light: true; title: ; notranslate">
select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_CUSTOM_OPSMGR_2007_AGENT_SETTING_2_0 on SMS_G_System_CUSTOM_OPSMGR_2007_AGENT_SETTING_2_0.ResourceId = SMS_R_System.ResourceId where SMS_G_System_CUSTOM_OPSMGR_2007_AGENT_SETTING_2_0.ManagementGroup = &quot;TYANG&quot;
</pre>
<p>All OpsMgr agents managed by OpsMgr Management Server SCOM02:</p>
<pre class="brush: sql; light: true; title: ; notranslate">
select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_CUSTOM_OPSMGR_2007_AGENT_SETTING_2_0 on SMS_G_System_CUSTOM_OPSMGR_2007_AGENT_SETTING_2_0.ResourceId = SMS_R_System.ResourceId where SMS_G_System_CUSTOM_OPSMGR_2007_AGENT_SETTING_2_0.ManagementServer = &quot;SCOM02.corp.tyang.org&quot;
</pre>
<p>All OpsMgr Management Servers:</p>
<pre class="brush: sql; light: true; title: ; notranslate">
select *  from  SMS_R_System inner join SMS_G_System_CUSTOM_OPSMGR_2007_SERVER_SETTING_2_0 on SMS_G_System_CUSTOM_OPSMGR_2007_SERVER_SETTING_2_0.ResourceId = SMS_R_System.ResourceId where SMS_G_System_CUSTOM_OPSMGR_2007_SERVER_SETTING_2_0.IsServer = 1
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2011/10/12/extend-configmgr-hardware-inventory-to-capture-opsmgr-configurations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Clean Up Old Hardware Inventory Data</title>
		<link>http://blog.tyang.org/2011/10/09/clean-up-old-hardware-inventory-data/</link>
		<comments>http://blog.tyang.org/2011/10/09/clean-up-old-hardware-inventory-data/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 08:42:30 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCCM]]></category>
		<category><![CDATA[Hardware Inventory]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=720</guid>
		<description><![CDATA[In SCCM, after removing WMI classes that are no longer required from configuration.mof and sms_def.mof, the inventory data still exists in few places. If you decide to clean them up, MyITForum.com has a great WIKI page for SCCM hardware inventory which talked about different ways to clean up hardware inventory data. I have tried the [...]]]></description>
			<content:encoded><![CDATA[<p>In SCCM, after removing WMI classes that are no longer required from <strong>configuration.mof</strong> and <strong>sms_def.mof</strong>, the inventory data still exists in few places.</p>
<p>If you decide to clean them up, MyITForum.com has a great <a href="http://www.myitforum.com/myITWiki/sccminv.ashx">WIKI page for SCCM hardware inventory</a> which talked about different ways to clean up hardware inventory data.</p>
<p>I have tried the free <a href="http://www.sccmexpert.com/site_sweeper.aspx">SiteSweeper</a> tool from SCCMExpert.com which was mentioned in the WIKI page. It’s easy to use and you can remove multiple classes from site database at once:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image12.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb12.png" alt="image" width="580" height="378" border="0" /></a></p>
<p>Other than removing the data from site databases throughout the hierarchy, the WMI class which you defined in the configuration.mof still exists in the client. I didn’t bother to look further to find tools/utilities to delete WMI classes, but simple found a sample vbscript from MSDN to modify WMI classes, and modified a little bit:</p>
<p><strong>DeleteWMIClass.vbs:</strong></p>
<pre class="brush: vb; title: ; notranslate">
wbemCimtypeString = 8             ' String datatype
Set objSWbemService = GetObject(&quot;Winmgmts:root\cimv2&quot;)
Set objClass = objSWbemService.Get()
objClass.Path_.Class = &quot;&lt;name of WMI class you wish to delete&gt;&quot;

' Remove the new class and instance from the repository
objClass.Delete_()
If Err &amp;lt;&amp;gt; 0 Then
WScript.Echo Err.Number &amp;amp; &quot;    &quot; &amp;amp; Err.Description
Else
WScript.Echo &quot;Delete succeeded&quot;
End If

' Release SwbemServices object
Set objSWbemService = Nothing
</pre>
<p>To modify it, specify the WMI class you wish to delete on line 4. If the WMI class is not located in root\CIMV2 namespace, change line 2 as well.</p>
<p>I created a package in SCCM and advertised it to all systems.</p>
<p><strong><span style="color: #ff0000;">Note</span></strong>: When you create the program, make sure you use the syntax “Cscript DeleteWMIClass.vbs” so the output is redirected to command prompt rather than a message box.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2011/10/09/clean-up-old-hardware-inventory-data/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Error 80041001 in InventoryAgent.log after mof files modifications</title>
		<link>http://blog.tyang.org/2011/10/09/error-80041001-in-inventoryagent-log-after-mof-files-modifications/</link>
		<comments>http://blog.tyang.org/2011/10/09/error-80041001-in-inventoryagent-log-after-mof-files-modifications/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 06:39:23 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCCM]]></category>
		<category><![CDATA[Hardware Inventory]]></category>
		<category><![CDATA[mof files]]></category>
		<category><![CDATA[RegKeyToMOF]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=715</guid>
		<description><![CDATA[I’ve been playing with SCCM mof files this weekend. After I’ve extended configuration.mof and sms_def.mof files to inventory a registry key during hardware inventory, I noticed below error logged in InventoryAgent.log on SCCM client: Unknown error encountered processing an instance of class &#60;name of the WMI class&#62;: 80041001 I checked the SCCM client, the WMI [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been playing with SCCM mof files this weekend. After I’ve extended configuration.mof and sms_def.mof files to inventory a registry key during hardware inventory, I noticed below error logged in InventoryAgent.log on SCCM client:</p>
<p>Unknown error encountered processing an instance of class &lt;name of the WMI class&gt;: 80041001</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image10.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb10.png" alt="image" width="580" height="95" border="0" /></a></p>
<p>I checked the SCCM client, the WMI class was created correctly, but the inventory data was not loaded in the SCCM database therefore I could not view it in Resource Manager.</p>
<p>After gone through both configuration.mof and sms_def.mof many times made sure they are 100% correct, I found this error is actually caused by a bug in SCCM 2007.</p>
<p>Because the SCCM client I’m using for testing is a Windows 2008 R2 machine (therefore 64 bit) and the issue with 64 bit client is documented <a title="KB2617545" href="http://support.microsoft.com/kb/2617545"><strong>here</strong></a>.</p>
<p>Also, while I was playing with mof files, I found this awesome tool called <strong>RegKeyToMOF</strong>. The current version is v3.0 and can be found <a title="RegKeyToMOF v3.0 download" href="http://myitforum.com/cs2/files/folders/proddocs/entry152945.aspx"><strong>here</strong></a>. It supports SMS 2003, SCCM 2007 and SCCM 2012 Beta 2.</p>
<p>it automatically generates mof extensions for you when you select the registry key that you want to inventory:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image11.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb11.png" alt="image" width="580" height="366" border="0" /></a></p>
<p>If you are planning to use this tool to generate the configuration.mof and sms_def.mof extensions, please make sure you tick “<strong>Enable 64bits (for Regkeys not written in Wow6432Node)</strong>” if you have 64-bit SCCM clients in your environment (nowadays, I can’t imagine that you don’t!). This is also what above mentioned KB article suggested.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2011/10/09/error-80041001-in-inventoryagent-log-after-mof-files-modifications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding New Network Devices to SCOM Using PowerShell</title>
		<link>http://blog.tyang.org/2011/10/01/adding-new-network-devices-to-scom-using-powershell/</link>
		<comments>http://blog.tyang.org/2011/10/01/adding-new-network-devices-to-scom-using-powershell/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 13:16:18 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SCOM]]></category>
		<category><![CDATA[SCOM; Network Devices]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=704</guid>
		<description><![CDATA[Last week, I needed to write a PowerShell script to add iSCSI SAN devices into SCOM 2007 as network devices. I thought the script would be very straight forward, until I realised there is a limitation using SCOM PowerShell snap-in. To explain it, let me firstly go through how to do this in SCOM console [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, I needed to write a PowerShell script to add iSCSI SAN devices into SCOM 2007 as network devices. I thought the script would be very straight forward, until I realised there is a limitation using SCOM PowerShell snap-in.</p>
<p>To explain it, let me firstly go through how to do this in SCOM console and then I’ll compare this process with using SCOM PowerShell cmdlets.</p>
<p>So, to add a new network device using SCOM console, it’s pretty easy:</p>
<p>1. Launch Discovery Wizard and choose “Network Devices”</p>
<p>2. Enter the network device information</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb.png" alt="image" width="580" height="551" border="0" /></a></p>
<p>3. Select the device from discovery result and choose a <strong>proxy agent</strong> for this network device</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb1.png" alt="image" width="489" height="465" border="0" /></a></p>
<p>Please note the default proxy agent is set to the management server from previous step. it can be changed by click on Change button</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image2.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb2.png" alt="image" width="449" height="449" border="0" /></a></p>
<p>It lists all possible proxy agents. There are 3 management servers in my test environment, <strong>SCOM01</strong> is my RMS, <strong>SCOM02</strong> is a management server and <strong>SCOMGW01</strong> is a gateway server located in another untrusted forest. I have highlighted these 3 servers, notice the icon for management servers is different than other normal agents.</p>
<p>4. continue on and complete the rest steps of the wizard.</p>
<p><strong>Now, let’s look at how to do this in PowerShell:</strong></p>
<p>1. Get Network Device monitoring class</p>
<pre class="brush: powershell; title: ; notranslate">$networkdeviceclass = get-monitoringclass -name 'System.NetworkDevice'</pre>
<p>2. Create a new DeviceDiscoveryConfiguration object</p>
<pre class="brush: powershell; title: ; notranslate">$dc = new-devicediscoveryconfiguration -monitoringclass $networkdeviceclass –fromipaddress “192.168.1.253” -toipaddress “192.168.1.253”</pre>
<p>3. Define SNMP community string</p>
<pre class="brush: powershell; title: ; notranslate">$encoding = new-object System.Text.UnicodeEncoding

$encodedCommunityString = $encoding.GetBytes(&quot;tyang&quot;)

$dc.ReadOnlyCommunity = [System.Convert]::ToBase64String($encodedCommunityString)</pre>
<p>4. Default SNMP version is 2, if the network device requires version 1, set the device discovery configuration to use SNMP version 1:</p>
<pre class="brush: powershell; title: ; notranslate">$dc.snmpversion = 1</pre>
<p>5. Define the management server to be used in the discovery</p>
<pre class="brush: powershell; title: ; notranslate">$NWDeviceMS = Get-ManagementServer | Where-object {$_.displayname –ieq “SCOM02.corp.tyang.org”}</pre>
<p>6. Start discovery using the management server defined in step 5</p>
<pre class="brush: powershell; title: ; notranslate">$DiscoveryResult = Start-Discovery -managementserver $NWDeviceMS -DeviceDiscoveryConfiguration $dc</pre>
<p>7. If discovery is successful, add the device into SCOM.</p>
<pre class="brush: powershell; title: ; notranslate">if ($discoveryresult.monitoringtaskresults[0].status -ieq &quot;succeeded&quot;)
{
#code to add the device into SCOM
}</pre>
<p>Well, here’s the issue:</p>
<p><strong><span style="color: #ff0000;">if you use the Add-RemotelyManagedDevice cmdlet, you have to use a SCOM AGENT as the proxy agent. You CANNOT choose a management server as the proxy agent for the network devices you are about to add.</span></strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image3.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb3.png" alt="image" width="580" height="268" border="0" /></a></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image4.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb4.png" alt="image" width="580" height="160" border="0" /></a></p>
<p>The management server is not an agent, get-agent cmdlet does not return management servers:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image5.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb5.png" alt="image" width="580" height="122" border="0" /></a></p>
<p>And if I use the management server in Add-RemotelyManagedDevice cmdlet, it will fail:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image6.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb6.png" alt="image" width="580" height="208" border="0" /></a></p>
<p>Basically, object type mismatch&#8230;</p>
<p>So, if we want to use a management server as the proxy agent for network devices, we <strong>CANNOT</strong> use Add-RemotelyManagedDevice cmdlet. It is a limitation in SCOM PowerShell snap-in. Instead, There is a method in the management server object called “<span style="color: #ff0000;"><strong>InsertRemotelymanagedDevices</strong></span>”:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image7.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb7.png" alt="image" width="450" height="565" border="0" /></a></p>
<p>we have to use this method to add network devices.  Therefore, the script for step 7 should be:</p>
<pre class="brush: powershell; title: ; notranslate">if ($discoveryresult.monitoringtaskresults[0].status -ieq &quot;succeeded&quot;)
{
$NWDeviceMS.InsertRemotelyManagedDevices($DiscoveryResult.custommonitoringobjects)
}</pre>
<p>8. Check result:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image8.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb8.png" alt="image" width="580" height="266" border="0" /></a></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/10/image9.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/10/image_thumb9.png" alt="image" width="579" height="303" border="0" /></a></p>
<p>As you can see, the device has been successfully added.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2011/10/01/adding-new-network-devices-to-scom-using-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event ID 29104 on SCOM RMS cluster</title>
		<link>http://blog.tyang.org/2011/09/30/event-id-29104-on-scom-rms-cluster/</link>
		<comments>http://blog.tyang.org/2011/09/30/event-id-29104-on-scom-rms-cluster/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 11:59:20 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCOM]]></category>
		<category><![CDATA[SCOM; RMS Cluster]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=678</guid>
		<description><![CDATA[First of all, apologies for not been able to blog for over a month. I changed jobs. I started my new job 4 weeks ago, with all the things going on, I couldn’t find time to sit down and write blog articles. I am now working in a large “System Center Shop” which consists of [...]]]></description>
			<content:encoded><![CDATA[<p>First of all, apologies for not been able to blog for over a month. I changed jobs. I started my new job 4 weeks ago, with all the things going on, I couldn’t find time to sit down and write blog articles. I am now working in a large “System Center Shop” which consists of SCCM, SCOM, SCVMM, Opalis, SCDPM and Hyper-V that spread over Australia national wide. so hopefully, my future blogs will have posts related to other System Center products as I get my hands on these products, not just SCCM and SCOM.</p>
<p>Anyways, in the last couple of days, I noticed on the 2-Node RMS cluster at work, when RMS is running on Node B, Event ID 29104 is logged in Operations Manager event log:</p>
<p><strong><em>“OpsMgr Config Service failed to send the dirty state notifications to the dirty OpsMgr Health Services. This may be happening because the Root OpsMgr Health Service is not running.”</em></strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/09/image.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/09/image_thumb.png" alt="image" width="580" height="333" border="0" /></a></p>
<p>This event was only generated when RMS was running on Node B, also, when Node B was the active node, RMS health state was greyed out in SCOM console. If I fail over RMS to Node A, everything is fine.</p>
<p>After spent some time troubleshooting the issue, I have found there are some registry keys mismatch between 2 nodes, they are under <strong>HKLM\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Server Management Groups\<em>&lt;Management Group Name&gt;</em>\</strong></p>
<p>On node B, “IsRootHealthService” is set to 0, Node A is set to “1”</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/09/image1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/09/image_thumb1.png" alt="image" width="580" height="158" border="0" /></a></p>
<p>Also on node B, there is a set of sub keys “Parent Health Services”. this set of keys should not exist in RMS:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/09/image2.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/09/image_thumb2.png" alt="image" width="580" height="170" border="0" /></a></p>
<p>So, to fix the issue, I firstly failed over RMS to node A, then changed “IsRootHealthService” on node B to “1” and deleted “Parent Health Services” key from node B. After that, I failed RMS back to node B, the 29104 events were no longer been logged and the RMS health state is not grey anymore.</p>
<p><span style="color: #ff0000;">Again, I did not consult Microsoft on this one, please take a back up of the registry keys before you change it and I am not responsible for any damages it may cause.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2011/09/30/event-id-29104-on-scom-rms-cluster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell script to backup unsealed SCOM MPs</title>
		<link>http://blog.tyang.org/2011/08/17/powershell-script-to-backup-unsealed-scom-mps/</link>
		<comments>http://blog.tyang.org/2011/08/17/powershell-script-to-backup-unsealed-scom-mps/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 23:40:49 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCOM]]></category>
		<category><![CDATA[Backup Management Packs]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=668</guid>
		<description><![CDATA[Not sure if anyone has written this before. I have written this simple script to backup all unsealed management packs. I have scheduled it to run daily on RMS via Windows Task Scheduler. How does it work: Backup unsealed MPs to a local folder. Delete older backups from local folder robocopy backup from local folder [...]]]></description>
			<content:encoded><![CDATA[<p>Not sure if anyone has written this before. I have written this simple script to backup all unsealed management packs.</p>
<p>I have scheduled it to run daily on RMS via Windows Task Scheduler.</p>
<p><strong>How does it work:</strong></p>
<ol>
<li>Backup unsealed MPs to a local folder.</li>
<li>Delete older backups from local folder</li>
<li>robocopy backup from local folder to a remote location using purge option (Anything that not exist from source will be deleted from destination. Therefore old backups are deleted from remote folder as well.)</li>
</ol>
<p><strong>Preparing the script:</strong></p>
<p>Modify line 21-23 to suit your environment</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image14.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb14.png" alt="image" width="580" height="81" border="0" /></a></p>
<p><strong>$backuproot</strong> – local folder where MPs are backed up to.</p>
<p><strong>$remoteLocation</strong> – Remote location where backups are robocopied to.</p>
<p><strong>$daysToKeep</strong> – retention period</p>
<p>Finally, make sure you the account scheduled task runs under has appropriate rights in SCOM.</p>
<p>Download the script <a href="http://blog.tyang.org/wp-content/uploads/2011/08/Backup-UnsealedMPs.zip">HERE</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2011/08/17/powershell-script-to-backup-unsealed-scom-mps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>“Orphaned” Maintenance Windows for SCCM clients</title>
		<link>http://blog.tyang.org/2011/08/16/orphaned-maintenance-windows-for-sccm-clients/</link>
		<comments>http://blog.tyang.org/2011/08/16/orphaned-maintenance-windows-for-sccm-clients/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 01:53:41 +0000</pubDate>
		<dc:creator>Tao Yang</dc:creator>
				<category><![CDATA[SCCM]]></category>
		<category><![CDATA[SCCM Clients Maintenance Windows]]></category>

		<guid isPermaLink="false">http://blog.tyang.org/?p=651</guid>
		<description><![CDATA[Last week, in my SCCM test environment, I noticed there are several maintenance windows applied to clients that I had no idea where were they come from. Symptoms: When using SCCM Client Center, it shows this particular client (MGMT01) has 3 maintenance windows (service window) assigned to it: PolicySpy from ConfigMgr 2007 Toolkit also shows [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, in my SCCM test environment, I noticed there are several maintenance windows applied to clients that I had no idea where were they come from.</p>
<p><strong>Symptoms</strong>:</p>
<p>When using <a href="http://sourceforge.net/projects/smsclictr/">SCCM Client Center</a>, it shows this particular client (MGMT01) has 3 maintenance windows (service window) assigned to it:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image3.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb3.png" alt="image" width="580" height="345" border="0" /></a></p>
<p>PolicySpy from <a href="http://www.microsoft.com/download/en/details.aspx?id=9257">ConfigMgr 2007 Toolkit</a> also shows the same:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image4.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb4.png" alt="image" width="580" height="110" border="0" /></a></p>
<p>The problem is, there should ONLY be 1 maintenance window for this client:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image5.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb5.png" alt="image" width="580" height="143" border="0" /></a></p>
<p>and actually, there is <strong>ONLY 1</strong> maintenance window in total in my entire environment:</p>
<p>I ran <strong>“SELECT * from v_ServiceWindow”</strong> against the site database and there is only 1 row returned.</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image6.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb6.png" alt="image" width="580" height="146" border="0" /></a></p>
<p><strong>Background</strong>:</p>
<p>Sometime last year, I installed a new central site called “<strong>CEN</strong>” and set the existing primary site “<strong>TAO</strong>” as the child site.</p>
<p>The only legitimate maintenance window in my SCCM hierarchy should be the one showed above in the database, it is created for a collection I created called “All Windows Server 2008 R2 Systems (CEN0000E)” on central site “CEN”.</p>
<p>I suspect I might have created 2 maintenance windows for the 2 built-in collections “All Systems&#8221; (SMS00001)” and “All Windows Server Systems (SMS000DS)” on site “TAO” before I configured “TAO” as child primary under “CEN”. but it has been too long and I couldn’t remember it.</p>
<p><strong>Troubleshooting:</strong></p>
<p>1. I tried to reset SCCM clients policies using PolicySpy, it did not help. these maintenance windows came back after machine policy retrieval and evaluation and it is logged in PolicyEvaluator.log:</p>
<p><strong><em>Updating policy CCM_Policy_Policy4.PolicyID=&#8221;SMS00001-{bf9d2dba-eb0a-412f-9147-82f12b4f136a}&#8221;,PolicySource=&#8221;SMS:TAO&#8221;,PolicyVersion=&#8221;1.00&#8243;    PolicyAgent_PolicyEvaluator    16/08/2011 8:23:41 AM    3624 (0x0E28)</em></strong></p>
<p><strong><em>Applying policy SMS00001-{bf9d2dba-eb0a-412f-9147-82f12b4f136a}    PolicyAgent_PolicyEvaluator    16/08/2011 8:23:41 AM    3624 (0x0E28)</em></strong></p>
<p>2. Since I cannot modify the built-in collections from the child primary sites because they also exist in parent sites, and it is only a test environment, I removed parent-child relationship between CEN and TAO and waited overnight, then checked maintenance windows settings for SMS00001 and SMS000DS on TAO, there are no maintenance windows created for these 2 collections. So this step did not help me resolving the issue.</p>
<p>3. I then had a look at the policy table in both CEN and TAO site databases trying to find the policy for these orphaned maintenance windows using the policyID showed in PolicySpy:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image7.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb7.png" alt="image" width="580" height="251" border="0" /></a></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image8.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb8.png" alt="image" width="580" height="244" border="0" /></a></p>
<p>I ran <strong>“SELECT * FROM Policy where PolicyID  LIKE &#8216;SMS%&#8217;</strong>” on both site databases, “CEN” database returned nothing and “TAO” has returned 2 rows and the policyIDs match the ones for orphaned maintenance windows:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image9.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb9.png" alt="image" width="580" height="148" border="0" /></a></p>
<p>I deleted these 2 rows from <strong>Policy</strong> table:</p>
<pre class="brush: sql; light: true; title: ; notranslate">
delete FROM Policy where PolicyID = 'SMS00001-{bf9d2dba-eb0a-412f-9147-82f12b4f136a}'
delete FROM Policy where PolicyID = 'SMS000DS-{4fe54281-f3f1-4b9f-9d9e-d1eb12b4a87e}'
</pre>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image10.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb10.png" alt="image" width="580" height="177" border="0" /></a></p>
<p>and from <strong>PolicyAssignment</strong> table:</p>
<pre class="brush: sql; light: true; title: ; notranslate">
delete FROM PolicyAssignment where PolicyID = 'SMS00001-{bf9d2dba-eb0a-412f-9147-82f12b4f136a}'
delete FROM PolicyAssignment where PolicyID = 'SMS000DS-{4fe54281-f3f1-4b9f-9d9e-d1eb12b4a87e}'
</pre>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image11.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb11.png" alt="image" width="579" height="378" border="0" /></a></p>
<p>Then restarted <strong>SMS_EXECUTIVE</strong> and <strong>SMS_SITE_COMPONENT_MANAGER</strong> services on TAO site server (also the MP). – Not sure if this is required, I did it anyway.</p>
<p>Finally, I <strong>reset</strong> SCCM client policy via PolicySpy and initiated <strong>“Machine Policy Retrieval and Evaluation Cycle”</strong></p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image12.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb12.png" alt="image" width="244" height="210" border="0" /></a></p>
<p>Once evaluation is completed, SCCM Client Center is showing the correct maintenance windows setting:</p>
<p><a href="http://blog.tyang.org/wp-content/uploads/2011/08/image13.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blog.tyang.org/wp-content/uploads/2011/08/image_thumb13.png" alt="image" width="580" height="143" border="0" /></a></p>
<p>Since I need to do this to all SCCM clients (because SMS00001 = “All Systems” collection), I’ll create a software package with a batch file as program:</p>
<pre class="brush: plain; light: true; title: ; notranslate">
WMIC /Namespace:\\root\ccm path SMS_Client CALL ResetPolicy 1 /NOINTERACTIVE
WMIC /Namespace:\\root\ccm path SMS_Client CALL RequestMachinePolicy 1 /NOINTERACTIVE
</pre>
<p><span style="color: #ff0000;"><strong>Disclaimer</strong>: The purpose of this post is only to document the steps I have taken to resolve this particular issue in my <strong>TEST</strong> environment. I did not consult with any other parties (including Microsoft) during troubleshooting. Even though I have not seen any negative impacts after I implemented this change in my test environment, I am not responsible for any damages it may cause in other SCCM environments.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tyang.org/2011/08/16/orphaned-maintenance-windows-for-sccm-clients/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

