Home > OpsMgr > How To Associate Run As Profile to a script

How To Associate Run As Profile to a script

Recently i needed to run some scripts under a specific user. here are the steps that help me:

1. Open the console and go to “Administration”, go to “Run As Configuration” and choose “Profiles”

clip_image002

2. Right click on “Profiles” and choose “Create Run As Profile…”

clip_image002[4]

3. Create the profile and save it to a specific MP.

clip_image002[8]

Choose the run as account or create one and select the objects that this account will run under.

clip_image002[10]

4. When finished create the rule or monitor with the script and export the MP.

5. Edit the MP and search for the profile name and copy it:
<TypeDefinitions>
<SecureReferences>
<SecureReference ID="RunAsProfile_MyCustomProfile" Accessibility="Internal" />
</SecureReferences>
</TypeDefinitions>

6. Set the run as attribute in the monitor or rule (in this example in a unit monitor, marked in red)
<UnitMonitor ID="MyCustomMonitor" Accessibility="Public" Enabled="true" Target="MicrosoftWindowsLibrary6172210!Microsoft.Windows.Computer" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="true" Priority="Normal" Run As =”RunAsProfile_MyCustomProfile" “TypeID="MicrosoftWindowsLibrary6172210!Microsoft.Windows.TimedScript.TwoStateMonitorType" ConfirmDelivery="false">

7. Now it’s time to set the user account which the script will run under, search the script body and add the marked test after the </scriptBody> tag:
<ScriptBody>’ Enter a script that outputs a property bag ‘ Example VBScript: ‘ ‘ Dim oAPI, oBag ‘ Set oAPI = CreateObject("MOM.ScriptAPI") ‘ Set oBag = oAPI.CreatePropertyBag() ‘ Call oBag.AddValue("Status","OK") ‘ Call oAPI.Return(oBag)</ScriptBody>
<SecureInput>$RunAs[Name=”RunAsProfile_MyCustomProfile”]/Domain$[Name=”RunAsProfile_MyCustomProfile”/UserName$</SecureInput>

8. and that’s it. import the MP and check if it works.

Advertisements
Categories: OpsMgr Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: