...
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 Workflow Studio will reload the Workflow. In the screenshot below, we are saving the Workflow with the Name MSTeamsPowershellWF.
Insert excerpt IL:Folder Structure Callout IL:Folder Structure Callout name FolderStructure nopanel true 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 CallGetTeamsCmdlet 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.
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.MSTeams to make the AzXPowerShellActivity work with Microsoft Teams Powershell.
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) { //TODO: Set activity properties here. try { PS.PSCommand cmd = new PS.PSCommand(); cmd.IsScript = true; cmd.CommandText = " Get-TeamUser -GroupId 06f979d3-78be-455c-8bb1-335788a92928 | ConvertTo-Json"; var commands = new List<PS.PSCommand>(); commands.Add(cmd); this.CurrentWorkflow.CallGetTeamsCmdlet.PSServiceType = AzPowerShellType.MSTeams; this.CurrentWorkflow.CallGetTeamsCmdlet.AccountStoreID = 2615; this.CurrentWorkflow.CallGetTeamsCmdlet.Commands = commands; this.CurrentWorkflow.CallGetTeamsCmdlet.RestrictDelayToSameServer = true; this.CurrentWorkflow.CallGetTeamsCmdlet.EnablePassiveResultsHandling = false; this.CurrentWorkflow.CallGetTeamsCmdlet.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"); } }
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 ShowUserResults and used the same text for the description.
Select the AzXPowerShellActivity in the workflow or GetCallMsOnlineCmdlet Activity in this example. Right-click on the Activity and select Edit Get/Set Data logic in the context menu. Paste the code into the GetDataCode method.
Code Block public virtual void SetDataCode(uni.WorkflowExecutor context, uni.IActivity activity) { this.CurrentWorkflow.ShowUserResults.Result = this.CurrentWorkflow.CallGetTeamsCmdlet.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.
...