System Center Orchestrator 2012 Beta: Using Run .Net Script Activity – PowerShell: Inputting and Returning Data

zip Coretech-SiteDashboard-v1.zip 4.78 kB
Downloaded 236 times

This article describes how to use the Run .Net Activity to run PowerShell Scripts.

I have created an example runbook which does the following:

  1. Start once every minute.
  2. Read a text file containing a list of sites/servers.
  3. Parse the list to PowerShell script.
  4. PowerShell script tried to ping each address and get the response time.
  5. PowerShell script output formatted HTML, ready to put inside a HTML Table, containing the addresses and response time.
  6. Runbook writes a web site based on a HTML template.

The result is a website, in my case it looks like this:

image

NB! some websites/server might not answer on ping requests, that is why some in this case have “No Response” even when they are working. Of cause you have to bear in mind that you cannot use this method for these kind of sites.

The runbook looks like this:

image

How to create the runbook:

  • Create a text file containing all the addresses you want to ping. All addresses should be surrounded by Quotes ” “.

image

  • Create new runbook
  • Drag a “Monitor Date/Time” into the new runbook and double click it.
  • Select “Details” tab and put in the following values

image

  • Drag a “Read line” activity into the runbook.
  • Create link from “Monitor Data/Time” to “Read Line”
  • Double click “Read Line”
  • Select “Details” tab and setup the activity to read the file you created:

image

  • We need to change the output of the read line, to use the flatten behavior. This means that the next activity in the line is only called once. All the read line will be flattened into one result sperated by ,
  • Check the “Flatten” checkbox and select “Separate with” and type “,”. It should look like this:

image

  • Drag a “Run .Net Script” into the runbook.
  • Link the “Read Line” activity to the “Run .Net Script” Activity
  • Double click “Run .Net Script”.
  • First of we need to type in the script and setup the “input”
  • Paste this script into the “Script” block:
$output = ""

foreach ($site in $sites)
{
	$ResponseTime = (Get-WmiObject -Query "SELECT * FROM Win32_PingStatus where address = '$site'").ResponseTime
		if ($ResponseTime -ge 0)
		{
		   $output += "<tr><td>$site</td><td>$ResponseTime ms</td></tr>"
		}
		else
		{
		   $output += "<tr><td>$site</td><td>No Response</td></tr>"
		}

	$ResponseTime = $null

}

  • This script use an array as input for the “foreach” called $sites. this is the input we need.
  • add this as the first line in the script, above the pasted text.

$sites =

  • Right click next to the “=” and select  Subscribe -> Returned Data

image

  • Now we need to find the data we want to paste inside the script. since we added the “Flatten” data behavior in the Read Line, it will automatically send all the info as “server”,”server2″,”server3″ and so on. Select “Read line” and “Line Text”

image

  • the result should look like this:

image

  • Now we need to setup the returning of the data. Select the tab called “Published Data”. Click “Add..”
  • In the “name” field type “HTML Output”
  • Select Type “String” since we a returning HTML string data.
  • In the “Variable name” field type “output”. This describes which variable to read, remember not to add the $ in front of the variable name!

image

  • Click OK

image

  • Now your Run .Net Script activity is complete
  • Drag a “Write Web Page” activity into the Runbook.
  • Create a Link from “run .Net Script” to “Write Web Page”.
  • Double click “Write Web Page” Activity.
  • In the Title field, write “Site Dashboard”
  • In the Text field, use the same technique as in the “Run .Net Script” to subscribe to The returned data from the “HTML Output” property of the “Run .Net Script” Activity.
  • In the Template field, select the template that you want to use. This article contains a template you can use.
  • a template for this activity is a normal HTML website, that have one extra tag added called <DOC-TEXT>. at runtime, this tag will be replaced by the text in the “Text” field.

image

  • Setup the output filename as a HTML file either on the local server or on a UNC path.
  • The tab should look like this:

image

  • The runbook is complete!
  • Test the runbook in the testing console. It creates a website using the template called “Dashboard.html”. Open this website in your browser.
  • The attached template for the site has a auto refresh every 5 seconds, which means you can use it for example a big screen in your department.

This is the first runbook I publish, more will be published soon. Please share your comments and feedback or ideas.


Comments (%):

  1. Vincent says:

    Hello,
    jakob, I start to use Orchestrator 2012 since few days, and I meet a problem, to put a published variable (from scsm 2012) in a powershell variable. The problem I mean is that publish variable containt CRLF. The variable is near xml, and even I cast the destination variable I was not able to store the object scsm proproperties to a standard powershell variable ($toto).
    Have you any idee about what i have to do .

    Thank for your answer.

    Vincent from France.

Leave a Reply

CAPTCHA Image
(required)