Grant Teams policies to users using PowerShell using Grant-CsUserPolicyPackage
In order to apply Teams policies to users using PowerShell using Grant-CsUserPolicyPackage you can do this on a user per user basis otherwise you can use the below script to do this in batch.
First you will need to get your password into a SecureString using the below code
Read-Host -prompt “Enter password to be encrypted” -assecurestring | convertfrom-securestring | out-file SecureString.txt
Once you have this file you can place it in the same directory as the below script, change the parameters in bold to your admin username, group and policy. The script when ran will pull the object id’s of the groups and users and then assign them using Grant-CsUserPolicyPackage
Note – Running this against large numbers of users is time consuming and can take well over 15 minutes for ~250 users.
$pass = cat SecureString.txt | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist “admin@yourdomain.onmicrosoft.com“,$pass
Connect-AzureAD -Credential $cred
Connect-MicrosoftTeams -Credential $cred
$group = Get-AzureADGroup -SearchString “Teams_Education_PrimaryStudent“
$members = Get-AzureADGroupMember -ObjectId $group.ObjectId -All $true | Where-Object {$_.ObjectType -eq “User”}
$members | ForEach-Object {Grant-CsUserPolicyPackage -PackageName Education_PrimaryStudent -Identity $_.UserPrincipalName}