www.contoso.se

Cloud and Datacenter Management by Anders Bengtsson

How-to build custom activities with QIK and PowerShell

In this blog post I will show you how to build two custom activities based on PowerShell commands. I will be using the Orchestrator beta and Quick Integration Kit 3. The Quick Integration Kit (QIK) enables you to extend your library of activities, with new custom integration packs and activities. QIK features a Command Line Interface (CLI) Wizard that allows you to describe how to run Command Line Interfaces (such as Windows Commands, SSH or PowerShell) and capture their output as Published Data. The QIK CLI Wizard provides a mechanism for very rapidly producing activities without the need for programming, given the readily available libraries of PowerShell from Microsoft and other community sources. In this blog post we will build two activities, one for counting files in a folder and one for list all files with a specific extension (for example mp3 files) in a folder. We will use QIK CLI that will help us build an integration pack (IP) around in this scenario two PowerShell commands. Let´s start with the one counting files

  1. Start Opalis QIK CLI. After default installation of QIK there will be a shortcut on your desktop
  2. Welcome to the Opalis QIK CLI, click Next
  3. Assembly QIK CLI, input a name for example ContosoFileAssembly
  4. Assembly QIK CLI, browse and input where the file will be created, for example C:\TEMP\FILEIP\ContosoFileIPAssembly.dll
  5. Assembly QIK CLI, click Next
  6. Commands, click Add…
  7. Add/Edit Command, General, input
    1. Name: Count Files in Folder
    2. Mode: Run Windows PowerShell
  8. Add/Edit Command, Arguments,
    1. Click Add under Parameters
    2. Add/Edit Parameter, input
      1. Name: Folder
      2. Usage mode: Command Argument
      3. Display Style: Folder
      4. Echo as published data: Check
      5. Click OK
    3. Add/Edit Command, Arguments, input “get-childitem $(Folder) | measure-object -property length” as command line. Click OK
  9. Add/Edit Command, Published Data, click Add
    1. Add/Edit Published Data, input
      1. Name: _Count (We use _ in front of all object-specific published data, then it is easier to see it in the list of published data when working in the console. Thanks to Robert Hearn for that tip)
      2. Property: Count
      3. Description: Number of files in folder
      4. Click OK
  10. Add/Edit Command, Published Data, click OK
  11. Commands, click Next
  12. Click Finish

We now have a dll file, a .NET assembly. We can now use the invoke .NET activity in the QIK IP to test the DLL before we build the IP. Start the System Center Orchestrator Runbook Designer and build a simple runbook to use the Invoke .NET activity and a Send Platform Event activity. To get the Invoke .NET activity you need to import the QIK IP. It is located at C:\Program Files (x86)\Opalis Software\Quick Integration Kit 3\Integration Packs after default QIK installation. Don’t forget to input a folder under Properties of the Invoke .NET activity. Configure the Send Platform Event activity to publish the count data from the Invoke .NET activity. Run the policy and verify that you get a result in the Send Platform Event activity.

Time to add the second activity, that should list all files with a specific extension in a folder.

  1. Start QIK CLI again, on the Welcome screen, click “Load from QIK CLI Assembly” and select your dll file (C:\TEMP\FILEIP\ContosoFileIPAssembly.dll)
  2. Assembly Details, click Assembly Information and raise version to 1.0.0.1. Click OK
  3. Assembly Details, click Next
  4. Commands, click Add…
    1. Input the following settings
      1. General, Name: List specific files in folder
      2. General, Mode: Run Windows PowerShell
      3. Arguments, Parameters, add
        1. Name: Folder
        2. Usage mode: Command Argument
        3. Display Style: Folder
        4. Echo as published data: Check
      4. Arguments, Parameters, add
        1. Name: File Extension
        2. Usage mode: Command Argument
        3. Display Style: Text
        4. Echo as published data: Check
      5. Arguments, Command Line, input “(Get-childitem $(Folder) | where {$_.Extension -eq ‘$Extension)’})
      6. Published Data, add
        1. Name: _Fullname
        2. Property: fullname
        3. Description: File path
      7. Published Data, add
        1. Name: _Name
        2. Property: name
        3. Description: Name of the file
      8. Published Data, add
        1. Name: _Length
        2. Property: Length
        3. Description: File size
      9. Published Data, click OK
    2. Commands, click Next
    3. When the wizard complete successfully you can can test the new command in the console with the .NET Invoke activity. Else, to build the integration pack, click Build Integration Pack. It is the same wizard that you can start direct from the shortcut “QIK Wizard”
  5. Opalis Quick Integration Kit Wizard, product details, input
    1. Category Name: Contoso File Management
    2. Manufacturer: Contoso
  6. Opalis Quick Integration Kit Wizard, product details, click Next
  7. Opalis Quick Integration Kit Wizard, objects, click Next
  8. Opalis Quick Integration Kit Wizard, dependencies, click Next
  9. Opalis Quick Integration Kit Wizard, Opalis Integration Pack File, input where to create the IP, for example C:\TEMP\FILEIP\ContosoFile.oip . Click Next
  10. Opalis Quick Integration Kit Wizard, The QIK Wizard Succeeded, click Finish

Now, use the Deployment manager to register IP with Orchestrator Management server and deploy IP to runbook servers and runbook designers. You can then use your new integration pack and activities in runbooks 🙂

Please note that this is provided “as is” with no warranties at all. If you want to take a look at my demo files send me a e-mail, I will upload them after some extra activites has been added. Download QIK here.

 

« »

© 2019 www.contoso.se. Theme by Anders Norén.