Trigerring powershell script via Orchestrator webservice

jansi rani krishnan 601 Reputation points
2021-06-01T10:16:34.77+00:00

(This is based on your inputs for my question https://learn.microsoft.com/en-us/answers/questions/410787/triggering-34run-net-script34-activity-in-orchestr.html)

Hi Andreas,

Thank you so much for the inputs. It is really helped me to design and start the implementation.

I have few points & questions based on your inputs.

  1. This integration is not a direct communication between SCSM and ServiceNow. We have "Azure Gateway" in between for security reasons. Azure APIs will just forward the requests from both ends. So, I think we cannot use the option "Command line utility tool by calling SCORunner.exe". I think i have left with only the first option "Call by an HTTP POST request URL of Orchestrator in SNOW" - Please confirm
  2. I have created a Runbook with below activities
    a. InitializeData (Receives the inputs from the webservice call)
    b. Run .Net Script (Process the input data)
    c. UpdateObject (How to fetch Object GUID to do the update on the selected ID?)
  3. I am thinking of an option to use hashtables with the properties to update and use the command "set-SCSMobject" in Run .Net Script" - Please advise
  4. Is there a way, where i can create a sample request and test using the postman? Awaiting for your valuable comments. Regards
    Jansi
System Center Orchestrator
System Center Orchestrator
A family of System Center products that provide an automation platform for orchestrating and integrating both Microsoft and non-Microsoft IT tools.
217 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 98,626 Reputation points MVP
    2021-06-03T10:05:14.277+00:00

    Hi @jansi rani krishnan ,

    here it's working like this (http://www.laurierhodes.info/?q=node/101):

    Runbook in Orchestrator:

    102035-image.png

    Get the details of runbook via Webservice and filter:

    102042-image.png

    Get the details of Runbook via Webservice manually:

    102028-image.png

    Get Parameters of Runbook via Webservice:

    102091-image.png

    The Script in the blog post needs just minor modification:

    102036-image.png

    The POST body will look like this (stored in the variable $POSTBody in the script):

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>  
    <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://w  
    ww.w3.org/2005/Atom">  
    <content type="application/xml">  
    <m:properties>  
    <d:RunbookId type="Edm.Guid">{bb7d6140-4992-4d33-84b4-8e943619ff07}</d:RunbookId>  
    <d:Parameters>&lt;Data&gt;&lt;Parameter&gt;&lt;ID&gt;{f40e1951-44f1-4075-9a26-f50ce77116cc}&lt;/ID&gt;&lt;Value&gt;IR12345&lt;/Value&gt;&lt;/Parameter&gt;&lt;/  
    Data&gt;</d:Parameters>  
    </m:properties>  
    </content>  
    </entry>  
    

    The result in Orchestrator if script finished:

    102053-image.png

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


3 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 98,626 Reputation points MVP
    2021-06-01T14:30:29.43+00:00

    Hi @jansi rani krishnan ,

    regarding 1: If you can't trigger the SCOJobRunner.exe the "Call by an HTTP Post" option might be the only one.

    regarding 2: You need to have the corresponding SCSM Incident ID in the triggering HTTP Post request and in the Initialize Data as a parameter/property. This way you can use the Incident ID (e.g. IR1234) in the activities following the Initialize Data activity.
    In general: You need the SCSM Incident ID stored in the SNOW Incident. You need the SNOW Incident ID stored in the SCSM Incident object. Otherwise its not possible to find the corresponding object in SCSM or SNOW if one object is updated in one of the systems.

    regarding 3: It's possible to use a hashtable with the command Set-SCSMObject: https://techcommunity.microsoft.com/t5/system-center-blog/using-smlets-beta-3-post-3-8211-using-set-scsmobject-to-bulk/ba-p/342952

    regarding 4: I've never used postman before. Sorry.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  2. Andreas Baumgarten 98,626 Reputation points MVP
    2021-06-01T18:57:23.167+00:00

    Hi @jansi rani krishnan ,

    Reg 1:
    SCOJobRunner.exe is connecting to the Orchestrator WebService. Wich means the computer executing the SCOJobRunner.exe needs to reach out to the Orchestrator WebService server.

    Reg 2:
    You can use a SCSM Get-Object activity to get the SCObject Guid, which is required by the SCSM Update-Object activity. Use the Incident ID as filter in the Get-Object activity. The SCObject Guid is an output property of the Get-Object activity.

    Reg 3:
    Updates in SCSM can be done with a PowerShell script (Set-SCSMObject) or/and an SCSM Update-Object activity. Choose the option that fits your needs.

    Reg 4:
    Are you talking about the HTTP Post request? If "yes":
    In the blog post http://www.laurierhodes.info/?q=node/101 is a section Retrieve the Runbook GUID and Retrieve Property GUIDs.
    With this details it should be possible to build the HTTP Post request.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  3. Andreas Baumgarten 98,626 Reputation points MVP
    2021-06-03T19:33:15.22+00:00

    Hi @jansi rani krishnan ,

    1. Yes. Just take a look at the screenshot ... The Runbook GUID is in the line above the title of the Runbook.
    2. The account needs the permission to access the web service. Just give it a try with opening the WebBrowser with the user account and connect to the Web Service URL
    3. I used the PowerShell Script from the linked blog post.
      1. Which screen are you referring to? The last screenshot is the Runbook Designer -> Log History and double-click on the latest job in the Log History

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten