Wednesday, July 1, 2020

Apply policy to group in Microsoft Team

Let's say that you wanted to apply certainly policy to a batch of users in Microsoft Team. As of now there is not much choice as UI has a limit of you can choose max 20 users and as per one of blog policy to the group will come sometime in July. There is one alternate approach. User out of box policy package in your team and attach that policy to users in the group. You can use below PowerShell script to run through the loop of users in a group and apply policy package to users. Please note that usually, it takes few hours to refreshed to show policy attached to users

$cred = Get-Credential "admin@domainname.onmicrosoft.com"
Connect-AzureAD -Credential $cred
Connect-MicrosoftTeams -Credential $cred

#Change Teaching Staff to your selected AD Group
$group = Get-AzureADGroup -SearchString "Security Group Creation"

$members = Get-AzureADGroupMember -ObjectId $group.ObjectId -All $true | Where-Object {$_.ObjectType -eq "User"}

#Name        : Education_Teacher
#Description : This is an Education_Teacher package
#
#Name        : Education_SecondaryStudent
#Description : This is an Education_SecondaryStudent package

#Change the PackageName to your chosen package
$members | ForEach-Object { Grant-CsUserPolicyPackage -PackageName Education_PrimaryStudent_RemoteLearning -Identity $_.UserPrincipalName}

No comments: