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. “
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.
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.
Save the Workflow with an appropriate name. Click on the Save icon, provide a File Name in the dialog, and click the Save button. Once you save the Workflow, the WFS will reload the Workflow. In the screenshot below, we are saving the Workflow with the Name MsOnlinePowershellWF.
Let’s add an activity. Click on the Activities Tab and Search for AzXPowerShellActivity. Drag and drop the Activity to the designer window.
Select the Activity, click on the Properties tab and change the Name to reflect your activity purpose. In this example, we are naming the Activity GetCallMsOnlineCmdlet and using the same text for the description.
Right-click on the Activity and select Edit Get/Set Data logic in the context menu.
Add a using reference to the PowerShell library.
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.
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; }
Now, add another activity to receive the results from the PowerShell commands. Search for DynamicPowershellResultsGrid in the Activities tab and drag-drop the Activity to the designer.
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.
Select the AzXPowerShellActivity in the workflow or GetCallMsOnlineCmdlet Activity in this example. Paste the code into the GetDataCode method.
public virtual void GetDataCode(uni.WorkflowExecutor context, uni.IActivity activity) { this.CurrentWorkflow.ShowResultsGrid.Result = this.CurrentWorkflow.GetCallMsOnlineCmdlet.Results; }
Please ensure all the activities are connected, and the necessary codes are included in the methods as instructed above.
Click on the Compile icon to compile the Workflow 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.
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.