Hello,
Yes, it is possible using a business rule, scheduled task, and a PowerShell script. The business rule triggering After creating a user will enable a Microsoft 365 account for the user, assign a license and mark the user by setting a custom Boolean attribute to true. The mark is required as the user creation in Microsoft Teams requires some time and the user will be added to the teams in a scheduled task. The task will process only the users that were marked in the business rule. A PowerShell script executed in the task will connect to Microsoft Teams, check if the user account exists, and if it does, the script will add the user to all teams. Then the script will clear the mark set by the business rule. To create the rule and the task:
i. Creating the business rule
- Launch Adaxes Administration console.
- In the Console Tree, right-click your service node.
- In the context menu, navigate to New and then click Business Rule.
- On step 2 of the Create Business Rule wizard, select the User object type.
- Select After creating a user.
- Click Next.
- Click Add an action.
- Select Activate or modify Microsoft 365 account.
- In the Actions Parameters section, select the Activate option.
- Select the required Microsoft 365 license.
- Click OK.
- Right-click the created action and then click Add New Action.
- Select Update the user.
- Click Add.
- In the Property to modify field, select custom Boolean attribute (e.g. CustomAttributeBoolean1). The attribute will be used to mark the user for further processing in a scheduled task.
- In the New value field, select True.
- Click OK twice.
- Click Next and finish creating the business rule.
ii. Creating the scheduled task
- Launch Adaxes Administration console.
- In the Console Tree, right-click your service node.
- In the context menu, navigate to New and then click Scheduled Task.
- On step 3 of the Create Scheduled Task wizard, select the User object type.
- Click Next.
- Click Add an action.
- Select Run a program or PowerShell script.
- Paste the below script into the Script field. In the script, the $markAttributeName variable specifies the LDAP name of the custom Boolean attribute used to mark the created users for further processing in the scheduled task. Must be the same as the one you specified on step 16 in section i.
$markAttributeName = "adm-CustomAttributeBoolean1" # TODO: modify me
# Get saved credentials
$username = $Context.RunAs.UserName
$password = $Context.RunAs.Password | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PsCredential($username, $password)
try
{
# Get the object ID in Microsoft 365
$objectId = ([Guid]$Context.TargetObject.Get("adm-O365ObjectId")).ToString()
}
catch
{
return # The user doesn't have a Microsoft 365 account
}
try
{
# Get the user in Microsoft Teams
Connect-MicrosoftTeams -Credential $credential
$user = Get-CsOnlineUser -Filter "Identity -eq '$objectId'"
if ($NULL -eq $user)
{
$Context.LogMessage("The user does not have a Microsoft Teams account", "Information")
return # User does not exist in Microsoft Teams
}
# Get all teams in Microsoft Teams
$teams = Get-Team
foreach ($team in $teams)
{
# Add the user to the team
Add-TeamUser -GroupId $team.GroupId -User $user.Identity
}
# Clear the mark attribute
$Context.TargetObject.Put($markAttributeName, $NULL)
$Context.TargetObject.SetInfo()
}
finally
{
# Close the connection and release resources
Disconnect-MicrosoftTeams
}
- Specify a description for the script.
- In the Run As section, select the This account option.
- Click Specify.
- Specify username and password of the Microsoft 365 account that has permission to add users to teams in Microsoft Teams.
- Click OK twice.
- Right-click the created action and then click Add Condition.
- Select If <property> <relation> <value>.
- Select If CustomAttributeBollean1 equals True. The specified attribute must be the same as the one whose name you specified in the $markAttributeName variable on step 8.
- Click OK.
- Click Next and finish creating the scheduled task.