Export (0) Print
Expand All

Adding Custom Activities to a Script Workflow

Published: June 24, 2013

Updated: June 24, 2013

Applies To: Windows PowerShell 3.0, Windows PowerShell 4.0, Windows Server 2012 R2



You can use built-in activities and custom activities in a Windows PowerShell® workflow. The library of built-in activities, including cmdlets that are implemented as activities, becomes available when you use the workflow keyword. In addition, developers can write custom activities in C# and include them in XAML workflows and script workflows.

To add a custom activity to a script workflow, use the Assembly parameter of the #Requires statement. The Assembly parameter identifies the assembly in which the custom activities are defined. When Windows PowerShell Workflow encounters the Assembly parameter, it loads the specified assembly and then processes the custom activities defined in the assembly so that they are available for use in the workflow. The Assembly parameter is valid only in workflows.

Valid value formats for the Assembly parameter of the #Requires statement are as follows:

  • Fully qualified assembly description

    #requires -Assembly MyCommand.Activities.dll Version=1.1.0.0, Culture=neutral, PublicKeyToken=11cd3656ab363bc4"
    
  • Fully qualified path to an assembly

    #requires -Assembly C:\Users\Admin01\MyCommand.Activities.dll
    
  • Relative path to an assembly in the local directory or in the global assembly cache

    #requires -Assembly MyCommand.Activities.dll
    

To use custom activities from multiple assemblies, enter multiple #Requires statements. The following sample workflow gets custom activities from two assemblies and uses them in the workflow.

workflow Test-Workflow
{
    #requires -Assembly C:\Users\Admin01\MyCommand.Activities.dll.dll
    #requires -Assembly MyFunction.Activities.dll.dll
    Get-CustomData -All
    Set-CustomDataLegacy -PSComputerName ...
}

For information about writing a custom activity, see "Creating a Workflow Activity from a Windows PowerShell Cmdlet" in the MSDN Library.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft