Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Workflow Studio supports workflow activities that can execute PowerShell cmdlets and retrieve results inside the same Workflow. The capability to execute PowerShell cmdlets makes it easier to implement custom use cases/scenarios that cannot be handled via out-of-the-box connectors and workflows.

The AzXPowerShellActivity is the workflow activity that allows developers to execute the cmdlets found in the following PowerShell modules:

  • AzureAD

  • EXO V2

  • MSOnline

  • MSTeams

  • SharePointOnline

The AzXPowerShellActivity will also soon support Graph PowerShell cmdlets too.

The AzXPowerShellActivity Activity relies upon the microservices running in the Azure tenant where the cmdlets are to be executed. There are microservices for each type of cmdlets supported by the AzXPowerShellActivity.

...

  • Developers can pass the commands and specify which microservice will handle the script execution in the AzXPowerShellActivity inside any workflow.

  • The AzXPowerShellActivity calls the SCIM connector to authenticate the user executing the command. The AzXPowerShellActivity exposes a property that allows setting the account store,

  • The SCIM microservice will then pass the commands to the microservice. The microservice will execute the commands in azure resources. The Workflow receives the results from the execution of the command. E.g., we can add an activity to execute the Add-TeamUser command and specify to run it in MS Teams PowerShell microservice. The specific microservice will execute the command and return the results to the Activity.

Anchor
Properties
Properties
Important Properties

The Major properties of TheDotNetFactory.Framework.PowerShell class are

Properties

Description

IsScript

IsScript is a boolean value indicating if the command text is the script.

CommandText

CommandText is a valid PowerShell command supported by the azure resource.

The major properties of the AzXPowerShellActivity class are

Properties

Description

PSServiceType

PSServiceType sets which microservice executes the current PowerShell script.

AccountStoreID

AccountStore that can authenticate the current user executing the PowerShell commands.

Commands

List of commands of type PSCommand.

RestrictDelayToSameServer

Set to True if any delay in the Activity should resume on the same workflow server that initiated the delay.

EnablePassiveResultsHandling

Set to True if the Activity should use the goto idle until results are available.

Azure AD PowerShell Workflow Example

In this tutorial, we will create and publish an Azure AD PowerShell Workflow using the WFS. Please read through the concepts and important properties to know more about how WFS supports executing PowerShell cmdlets. We will cover the following in this tutorial.

  • Create a workflow that uses AzXPowerShellActivity, which will run the command below in Azure AD Microservice. This command fetches DisplayName, Mail, and ObjectId attributes for the top 50 Azure Ad Users.

    Code Block
    Get-AzureADUser -Top 50 | Select DisplayName, Mail, ObjectId | ConvertTo-Json
  • We will include DynamicPowershellResultsGrid Activity in the Workflow to view the results in a grid.

  • Publish the Workflow

  • Verify the Workflow is working by executing the Workflow in EmpowerID. We should be able to see a grid with DisplayName, Mail, and ObjectId attributes for the top 50 Azure Ad Users.

Create Workflow

Please follow the instructions below to create an Azure AD PowerShell Workflow that uses AzXPowerShellActivity & DynamicPowershellResultsGrid.

Note

This tutorial assumes that the reader knows how to create a basic workflow. Please consider following the instructions here to create a basic workflow.

...

In the Workspace tree of Solution Explorer, right-click the Package node where you want to create the Workflow and select New Workflow > Flow Chart Workflow from the context menu.

...

...

The Workflow Designer will load a flowchart workflow with default shapes and names.

...

...

...

Code Block
using PS = TheDotNetFactory.Framework.PowerShell;

Paste the code for the SetDataCode method. Please ensure the following important property values are correctly set for the code to work.

...

PSServiceType : Set the value of PSServiceType to AzPowerShellType.AzureAD to make the AzXPowerShellActivity work with Azure AD.

AccountStoreID: Set the value to the right account store so that the current user executing the PowerShell commands can be authenticated.

Code Block
public virtual void SetDataCode(uni.WorkflowExecutor context, uni.IActivity activity)
        {
            try
            {
             PS.PSCommand cmd = new PS.PSCommand();
             cmd.IsScript = true;
             cmd.CommandText = "Get-AzureADUser -Top 50 | Select DisplayName, Mail, ObjectId | ConvertTo-Json";
 
             var commands = new List<PS.PSCommand>();
             commands.Add(cmd);
 
             this.CurrentWorkflow.GetADUsersCmdlet.PSServiceType = AzPowerShellType.AzureAD;
             this.CurrentWorkflow.GetADUsersCmdlet.AccountStoreID = 2615;
             this.CurrentWorkflow.GetADUsersCmdlet.Commands = commands;
             this.CurrentWorkflow.GetADUsersCmdlet.RestrictDelayToSameServer = true;
             this.CurrentWorkflow.GetADUsersCmdlet.EnablePassiveResultsHandling = false;
             this.CurrentWorkflow.GetADUsersCmdlet.MaxWaitLoopCount = 10;
             TdnfTrace.Current.TraceData(TraceEventType.Verbose, 411, "!!!!!######Starting to execute the command: " + cmd.CommandText);
            }
            catch(Exception ex)
            {
                TdnfTrace.Current.TraceData(TraceEventType.Verbose, 411, "!!!!!######Something blew up executing the command");
            }
      }

...

Select the Activity, click on the Properties tab and change the Name to something meaningful. In this example, we renamed it to ShowUserResults.

Paste the code into the GetDataCode method.

Code Block
 public virtual void GetDataCode(uni.WorkflowExecutor context, uni.IActivity activity)
         {
            this.CurrentWorkflow.ShowUserResults.Result = this.CurrentWorkflow.GetADUsersCmdlet.Results;
        }

...

...

Click on the Compile icon to compile the activity code.

...

Publish Azure AD PowerShell Workflow

We are all set to publish the Workflow. Please follow the instruction, and information about publishing the workflow items can be found here.

Verify the Workflow is Working

...

Log in to your EmpowerID portal.

...

Navigate to Object Administration → Workflows.

...

MSOnline PowerShell Workflow Example

This tutorial will create and publish an MSOnline PowerShell Workflow and execute a cmdlet using the WFS. Please read through the concepts and important properties to know more about how WFS supports executing PowerShell cmdlets. We will cover the following in this tutorial.

  • Create a workflow that uses AzXPowerShellActivity, which will run the command below in MS Online Microservice. This command “Gets contacts from Azure Active Directory. “

    Code Block
    Get-MsolContact | ConvertTo-Json
  • We will include DynamicPowershellResultsGrid Activity in the Workflow to view the results in a grid.

  • Publish the Workflow

  • Verify the Workflow is working by executing the Workflow in EmpowerID. We should be able to see a grid with Contacts from MS Online.

Create Workflow

Please follow the instructions below to create an MSOnline PowerShell Workflow that uses AzXPowerShellActivity & DynamicPowershellResultsGrid.

Note

This tutorial assumes that the reader knows how to create a basic workflow. Please consider following the instructions here to create a basic workflow.

...

In the Workspace tree of Solution Explorer, right-click the Package node where you want to create the Workflow and select New Workflow > Flow Chart Workflow from the context menu.

...

...

The Workflow Designer will load a flowchart workflow with default shapes and names.

...

Add a using reference to the PowerShell library.

Code Block
using PS = TheDotNetFactory.Framework.PowerShell;

Paste the code for the SetDataCode method. Please ensure the following important property values are correctly set for the code to work.

...

PSServiceType : Set the value of PSServiceType to AzPowerShellType.MSOnline to make the AzXPowerShellActivity work with Azure AD.

AccountStoreID: Set the value to the right account store so that the current user executing the PowerShell commands can be authenticated from the account store.

Code Block
 public virtual void SetDataCode(uni.WorkflowExecutor context, uni.IActivity activity)
        {
           PS.PSCommand cmd = new PS.PSCommand();
			 cmd.IsScript = true;
			 cmd.CommandText = "Get-MsolContact | ConvertTo-Json";

			 var commands = new List<PS.PSCommand>();
			 commands.Add(cmd);

			 this.CurrentWorkflow.GetCallMsOnlineCmdlet.PSServiceType = AzPowerShellType.MSOnline;
			 this.CurrentWorkflow.GetCallMsOnlineCmdlet.AccountStoreID = 2615;
			 this.CurrentWorkflow.GetCallMsOnlineCmdlet.Commands = commands;
			 this.CurrentWorkflow.GetCallMsOnlineCmdlet.RestrictDelayToSameServer = true;
			 this.CurrentWorkflow.GetCallMsOnlineCmdlet.EnablePassiveResultsHandling = false;
			 this.CurrentWorkflow.GetCallMsOnlineCmdlet.MaxWaitLoopCount = 10;
        }

...

Select the DynamicPowershellResultsGrid Activity, click on the Properties tab and change the Name to something meaningful. In this example, we renamed it to ShowResultsGrid and used the same text for the description.

...

Code Block
public virtual void GetDataCode(uni.WorkflowExecutor context, uni.IActivity activity)
    {
          this.CurrentWorkflow.ShowResultsGrid.Result = this.CurrentWorkflow.GetCallMsOnlineCmdlet.Results;
    }

...

Publish Azure AD PowerShell Workflow

We are all set to publish the Workflow. Please follow the instruction, and information about publishing the workflow items can be found here.

Verify the Workflow is Working

...

Log in to your EmpowerID portal.

...

...

Search the Workflow published earlier and click on the workflow name in the Run column to execute the Workflow.

...

You should be able to see the Grid that populates the users from the MSOnline.

...

stylefloat:left; position:fixed;
idarticleNav

IN THIS ARTICLE

...

Insert excerpt
IL:External Stylesheet
IL:External Stylesheet
nopaneltrue