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

Download “Coretech-SiteDashboard-v1.zip” Coretech-SiteDashboard-v1.zip – Downloaded 359 times – 5 KB

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:

  • 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.

By | 2011-08-01T09:58:00+00:00 August 1st, 2011|Automation, Powershell, Scripting & Development|1 Comment

About the Author:

Jakob Gottlieb Svendsen

Twitter: @JakobGSvendsen

Jakob Gottlieb Svendsen is a Microsoft Cloud and Data Center Management MVP (http://mvp.microsoft.com/en-us/default.aspx), Working as Global Lead Developer, Senior Consultant and Trainer at CTGlobal, where he is one of the driving forces in keeping CTGlobal a System Center Gold Partner and member of the System Center Alliance.

Since he started at Coretech in 2007, he has focused on Scripting and Development, primarily developing tools, extensions and scripts for the System Center Suite. His main area is Automation (including OMS/Azure Automation, Service Management Automation, PowerShell and Orchestrator). Another area is Windows Azure Pack / Azure Stack, where he does implementation, development, workshops and presentations. He is a world-wide renowned voice in the Automation field.

He is passionately devoted to the community, to which he contributes by being a moderator at TechNet and sharing his knowledge at http://blog.ctglobalservices.com/jgs

  • Co-founder: PowerShell User Group Denmark
  • Speaker at MMS 2016, Minneapolis (www.mmsmoa.com)
  • SCU Europe 2014, 2015, 2016 (www.systemcenteruniverse.ch)
  • Microsoft TechEd North America 2014, Houston
  • NIC 2012,2013,2014,2015, Oslo (www.nic.com)
  • Microsoft CampusDays 2011, 2013, Copenhagen
  • Microsoft TechDays 2015, Sweden (www.techdays.se)
  • Microsoft Partner Event: New in SC2012 SP1
  • User group meetings (PSUG.DK , SCUG.DK/BE/NO, AZMUG + more)
  • Microsoft Certified Trainer.
  • Microsoft Scripting Guys Forum Moderator

Main working areas:

  • Automation (Azure Automation, SMA, SCO)
  • Windows Azure Pack / Azure Stack
  • System CenterVisual Studio Team Services / Team Foundation Server
  • Development:C#.Net, VB.NET, VBScript, PowerShell, Service Manager, OpsMgr, ConfigMgr
  • Orchestrator
  • Windows Azure Pack / Azure Stack

Training:

  • Azure Automation
  • Service Management Automation
  • System Center Orchestrator
  • PowerShell, VBScript, C#.Net, VB.Net
  • Windows Azure Pack / Azure Stack Development Workshops

One Comment

  1. Vincent February 9, 2012 at 23:12 - Reply

    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 Comment