|
|
 
1 |
I’ve always said “girls make the smartest IT people”….and so it goes again in today’s post. I was talking to my friend Lizzie the other day about an OpsMgr script I wrote, and she got a bit off topic…and had a great idea! With all the talk of green IT, let’s talk about saving some green by reusing work we’ve already done. I’ll replay a bit of our conversation for you here simply because Lizzie tends to speak her mind and is usually hilarious in the process.
Lizzie: “You know, these two-state monitor scripts would be perfect for ConfigMgr”
Pete: “Girl, what’re you talkin’ about?”
Lizzie: “You know…for DCM???”
Pete: “You mean to check CIs [configuration items] in a baseline?”
Lizzie: “Yeah, you could recycle these for ConfigMgr...You do recycle don’t you? That’s hot.” (she frequently quotes Paris Hilton [or other ridiculous celebrities] for a laugh or for effect)
Pete: “That’s a good idea. Gee, you’re pretty smart.”
Lizzie: “Duh! No $%*#$ I’m smart!”
States of Being: OpsMgr Two-States versus ConfigMgr Two-State
Let’s look at Lizzie’s point a little more closely.
- In OpsMgr, a two-state monitor script looks for two conditions….healthy or not healthy
- In ConfigMgr, a script-based CI in a DCM baseline is generally looking for two states, compliant or not compliant.
There are some differences, but nothing we can’t handle in a few minutes time.
Converting Scripts to “The Other Side” – A Simple Example
So really, the transition is moderately to very easy depending on the script. It mostly depends on how much of the OpsMgr scripting API you have mingled in your OpsMgr script. Let’s do a quick conversion of one of our most simple samples here on SCC… This is an OpsMgr script designed to check the startup configuration of a Windows service (to make sure its set to start automatically). Notice the purpose of the script is configuration monitoring….appropriate for this example and DCM in general
Note: In truth, we could do this particular check as a registry-based CI, but sometimes we use scripts anyway for flexibility when we want to check multiple registry values as part of a single CI or we really need to log an event, etc. Good enough for purposes of demonstration here…I’m sure you get the point.
Here’s the OpsMgr Version of the Script. I’ve highlighted in red the bits we’ll need to lose in the transition. In the end, the script will actually become even more simple…
‘----------Start of OpsMgr Two-State Monitor Script------------------
'Declare variables
Dim objMOMAPI, objBag, wshShell
'Instantiate (create an instance) of MOMScriptAPI
Set objMOMAPI = CreateObject("MOM.ScriptAPI")
'Instantiate MOMScriptAPI and Create PropertyBag
Set objAPI = CreateObject("MOM.ScriptAPI")
Set objBag = objMOMAPI.CreateTypedPropertyBag(StateDataType)
'Read Registry Value
Set WshShell = WScript.CreateObject("WScript.Shell")
ReadRegValue = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\Spooler\Start")
If ReadRegValue = 2 Then
'Set state to GOOD
Call objBag.AddValue("State","GOOD")
Call objMOMAPI.Return(objBag)
Else
'Set state to BAD
Call objBag.AddValue("State","BAD")
Call objMOMAPI.Return(objBag)
Wscript.Quit()
End If
‘---------End of Script-------------
And now, the ConfigMgr version
You can see here, this resulting DCM script is dead simple and took about 60 seconds to convert. It checks the same value representing the service startup type and returns compliant or not compliant, 0 or a 1, true or false.
‘----------Start of ConfigMgr DCM Script------------------
'Declare variables
Dim wshShell
'Read Registry Value
Set WshShell = WScript.CreateObject("WScript.Shell")
ReadRegValue = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\Spooler\Start")
If ReadRegValue = 2 Then
'Return COMPLIANT
WScript.Echo "Compliant"
Else
'Return Not Compliant
WScript.Echo "NotCompliant"
End If
‘---------End of Script-------------
Conclusion
There’s all kinds of green IT. In this case we’re just recycling and saving some $green. After all, time is money.
Next Up….DCM and Heisenberg Uncertainty Principle
Follow System Center Central via Twitter and RSS
