Home > Microsoft, SCOM 2007 > Using a specific account for specific scripts in SCOM 2007

Using a specific account for specific scripts in SCOM 2007

In System Center Operations Manager 2007 you can choose an action account per server. Some management packs provide the possibility to choose a different account for some tasks. However, if you just want to run a specific script with a specific user account, the SCOM environment doesn’t provide default options to choose an account. There is a way to bypass the default behaviour in SCOM 2007 and provide your own account for a specific check.

Find out how

To prepare for a specific monitoring user follow these steps:

  • In “Administration|Run As Accounts”, choose “Create Run As Account”
  • Provide account details
  • CreateAccount
    Create a monitoring profile

  • In “Administration|Run As Profiles” choose “Create Run As Profile”
  • Provide profile details
  • Save it in a management pack of your choice (not the default management pack ofcourse)
  • CreateProfile

  • In the next step choos your account you created in the previous step
  • Now create your monitor (in the authoring section).
    See for basic instructions on how to create a monitor one of my previous posts: http://www.cupfighter.net/index.php/2009/10/check-your-sql-backup-automatically/

  • Save the monitor in the same management pack as you saved your profile
  • Write the script you want to run
  • Here is a sample script with some basic options for passing the output to the eventlog and to SCOM itself to set the state of the monitor and generate alerts. The script also contains some code to determine the user account that is used.

    Option Explicit
    Dim checkdotcomma, strStatus
    Dim objAPI, propertyBag
    Dim objWMIService, colProcesses, objProcess
    Dim strCurrentUser, User, Domain, strUserList

    On Error Resume next
    Const EVENT_TYPE_ERROR = 1
    Const EVENT_TYPE_WARNING = 2
    Const EVENT_TYPE_INFORMATION = 4

    ‘ Check if we are using the correct user for this check
    Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2″)
    Set colProcesses = objWMIService.ExecQuery(“select * from win32_process where Name=’cscript.exe’”)
    For Each objProcess in colProcesses
    If objProcess.GetOwner (User, Domain ) = 0 Then
    strCurrentUser = “Script has run under account: ” & Domain & “\” & User
    Else
    strCurrentUser = “Problem getting the owner for process ” & objProcess.Caption
    End If
    strUserList = strUserList & strCurrentUser
    Next

    Set objAPI = CreateObject(“MOM.ScriptAPI”)
    ‘ perform check on regional settings if numbers are using dots or commas
    ‘ replace this with your own code you want to run
    checkdotcomma = Mid(1/2,2,1)
    If checkdotcomma = “.” Then
    strStatus = “Ok”
    Call objAPI.LogScriptEvent(“CheckDotComma”,2000, EVENT_TYPE_INFORMATION,”Regional Settings are using a Dot (.). The user list is ” & strUserList )
    Else
    strStatus = “Error”
    Call objAPI.LogScriptEvent(“CheckDotComma”,2001, EVENT_TYPE_ERROR, “Regional Settings are using a Comma (,). The user list is ” & strUserList )
    End if

    ‘ return status to monitor
    Set propertyBag = objAPI.CreatePropertyBag ()
    Call propertyBag.AddValue (“Status”, strStatus)
    Call propertyBag.AddValue (“checkdotcomma”, checkdotcomma)
    Call objAPI.Return(propertyBag)

    Download the System Center Operations Manager 2007 Authoring Console

    http://www.microsoft.com/downloads/details.aspx?FamilyID=6c8911c3-c495-4a03-96df-9731c37aa6d7&displaylang=en

  • Open your monitor in this advanced authoring console
  • Now you can choose your run as profile user
  • ChooseRunAsProfile

    To make it bit more nice, export your management pack, and look up the Secure References.
    Replace all instances of the SecureReference ID with a more readable format, see below.

    <SecureReferences>
          <SecureReference ID="MonitoringUser" Accessibility="Internal" Context="System!System.Entity" />
        </SecureReferences>

    Reimport your managementpack and you are all set.

    Categories: Microsoft, SCOM 2007 Tags:
    1. No comments yet.
    1. No trackbacks yet.