29 oct. 2011

Export runbook or Opalis policies to visio or word

9 oct. 2011

Orchestrator 2012, runbooks and powershell

8 oct. 2011

Start a System Center Orchestrator 2012 Runbook through its webservice

Article updated the 26/11/2011 (to fix a bug with the Csharp and Orchestrator parameters)


With System Center Orchestrator 2012, you have the ability to connect to it through a web service.
Jakob Gottlied Svendsen is showing how to access to it:
  • to create an excel report
  • or to create a webpart for sharepoint 2010

I would like to show you how to write a simple C# application to access to this web service and execute a runbook with parameters.


1. Generating Custom Class from the web service
To be able to use the web service in .net, you will have to create a class file, containing the format and content of what the web service has to offer.
This is done by using a console application in .NET framework 3.5 called “DataSvcUtil”
  • Open a commandprompt
  • Run this command. The command creates a .CS file in the format of the web service.
%windir%\Microsoft.NET\Framework\v3.5\DataSvcUtil.exe” /dataservicecollection /version:2.0 /language:CSharp /out:ScorchEntities.cs /uri:http://orchestrator.server.com:81/Orchestrator.svc
  • Copy or move the file to the project folder
  • Add the file to the project (add>Existing Items)


2. Let's use the class to access to the web service
Ok, now you are ready to access to your class and so the webservice.
1. Connect webservice context using
Microsoft.SystemCenter.Orchestrator.WebService.OrchestratorContext
2. Retreive the runbook It is a generic method to access to a web service. You can have some help from the microsoft website http://msdn.microsoft.com/en-us/library/cc668796.aspx
var runbooks = from runbook in ScorchSVC.Runbooks

                           where runbook.Name == runbookname
                           select runbook;
3. You need to retreive the also all runbook's parameter.
            var runbookparamaters = from runbookparamater in ScorchSVC.RunbookParameters
                                    where runbookparamater.RunbookId == runbooks.Single().Id
                                    select runbookparamater;
4. Create a job
var job = Microsoft.SystemCenter.Orchestrator.WebService.Job.CreateJob(System.Guid.NewGuid(), runbooks.Single().Id, "user1", DateTime.Now, "user1", DateTime.Now);
5. Pass the parameter to job. I think it is the hardest thing. You need to know the format. In the step3, we have retreived the runbookparameterid and we will use it. The parameter Name is not enough, you need to have the id...
<Data>
<Parameter>
<Name>Parameter Name for example arg1 </Name>
<Id>Guid of the parameter so guid of arg1</Id>
<Value>the value :)</Value>
</Parameter>
<Parameter>
etc.
</Parameter
</Data>
6. Last step is to passe the job created to the context and apply the change.

            ScorchSVC.AddToJobs(job);

            ScorchSVC.SaveChanges();