Automation workflow enhancements allow you to add Azure or Office 365 modules in PowerShell and run the Office 365 services such as Skype for Business, Azure AD, and Azure PowerShell Az PowerShell scripts within existing Active Roles workflows.
As part of creating automation workflow, a new O365ScriptExecutionConfiguration activity is added to fetch the already configured tenant details. Select a tenant from the Select a Tenant to configure O365 Services drop-down list that displays all the tenants configured on the Active Roles Web Interface.
Selected tenant is displayed in This tenant will be used to configure O365 Services if the override tenant details is not provided textbox.
However, if required, you can override Office 365 script execution. Double-click on O365ScriptExecutionConfiguration and edit the O365 User and O365 Password workflow parameters.
NOTE: By default, the tenant is not selected.
If no tenant is selected and no override tenant details are provided, the workflow fails and the following error message appears:
Please select a configured Tenant from the Select a Tenant to configure O365 Services drop-down or provide valid Tenant Id, Login username and password to override details from workflow.
If the tenant is selected in the drop-down and the override details are also provided, the O365 services will be configured using the override details.
Prerequisites to run the Office 365 workflow scripts
The following PowerShell modules must be installed to the system running Active Roles to run the Office 365 PowerShell script execution activity.
- Azure Active Directory (Azure AD)
- Azure PowerShell Az
- Microsoft Teams (includes Skype for Business)
As Exchange Online is connected to Exchange Online PoweShell, make sure that https://outlook.office365.com/powershell-liveid/ is not be blocked and network connectivity is available.
Creating an Office 365 automation workflow definition
To create an Office 365 automation workflow definition
- In the Active Roles console tree, expand Configuration > Policies, right-click Workflow, and select New > Workflow.
- Follow the steps in the New Workflow wizard:
-
From the tool box within the workflow, select O365ScriptExecutionConfiguration and configure the Office 365 automation workflow.
-
From the workflow, select the Script activity and configure the script activity to point to the PowerShell script and function to execute.
Sample Office 365 workflow scripts
$context.O365ImportModules(array of modules)
This script enables the multiple modules specified in the array to be loaded and creates a connection to the modules with the login details retrieved through O365ScriptExecutionConfiguration activity. The O365 User and O365 Password parameters that are configured earlier within workflow are used.
$array = @(“MSOnline”, “Lync”) $context.O365ImportModules($array) $context.O365RemoveAllModulesSessions()
$context.O365ImportModule (module)
This script enables the single module specified in the script to be loaded.
Example:
$context.O365ImportModule(“AzureRm) #latest version azureRm is imported $context.O365ImportModule(“AzureRm, 4) #latest version azureRm version 4 is imported $context.O365RemoveAllModulesSessions()
$context.O365ExecuteScriptCmd(string/cmd )
Passing any string or command specified in the script will execute and return the results as PSObject.
$context.O365RemoveAllModulesSessions()
This script disconnects the PSSessions and removes the modules from the PowerShell pool, allowing to import new modules again.
Example:
#Get a list of disabled users and Directory Roles available $_usersinroles= @() $_default_log = "C:\temp\Roles.csv" $context.O365ImportModule("AzureAD") $context.O365ExecuteScriptCmd("get-azureaduser -filter 'accountEnabled eq false'" +" | Export-Csv " +"c:\temp\DisabledUsers.csv" +" -NoTypeInformation") $context.O365ExecuteScriptCmd("Get-AzureADDirectoryRole | Export-csv "+$_default_log ) $context.O365RemoveAllModulesSessions()