This script will add or remove members from a Teams App Permission Policy and an App Setup Policy using PowerShell. You will need to change the names of the policies in the variables, and for assigning members you will need the Group Object ID so that you can assign the policy to the group members.
The blocks are commented out, so that you can highlight the code block and run the assign or unassign script separately of each other.
Connect-MicrosoftTeams
$AppPermissionPolicy = "Custom App Policy Name"
$AppSetupPolicy = "Custom App Setup Policy Name"
<# --------------------- Assign Policies to Users in an AAD Group -----------------------
$GroupObjectId="00000000-0000-0000-0000-000000000000"
$GroupMembers = Get-AzureADGroupMember -ObjectId $GroupObjectId -All $true | select UserPrincipalName
$GroupMembers | ForEach {
Grant-CsTeamsAppPermissionPolicy -Identity $_.UserPrincipalName -PolicyName $AppPermissionPolicy
Grant-CsTeamsAppSetupPolicy -Identity $_.UserPrincipalName -PolicyName $AppSetupPolicy
}
#--------------------------------------------------------------------------------------#>
<# --------------------- Remove App Permission Policy from Users ------------------------
$AppPermissionPolicy = "Custom App Policy Name"
$AppSetupPolicy = "Custom App Setup Policy Name"
<# --------------------- Assign Policies to Users in an AAD Group -----------------------
$GroupObjectId="00000000-0000-0000-0000-000000000000"
$GroupMembers = Get-AzureADGroupMember -ObjectId $GroupObjectId -All $true | select UserPrincipalName
$GroupMembers | ForEach {
Grant-CsTeamsAppPermissionPolicy -Identity $_.UserPrincipalName -PolicyName $AppPermissionPolicy
Grant-CsTeamsAppSetupPolicy -Identity $_.UserPrincipalName -PolicyName $AppSetupPolicy
}
#--------------------------------------------------------------------------------------#>
<# --------------------- Remove App Permission Policy from Users ------------------------
$filter = "TeamsAppPermissionPolicy
-eq '$($AppPermissionPolicy)'"
$GroupMembers = Get-CsOnlineUser -Filter $filter | Select UserPrincipalName
$GroupMembers | ForEach {
#New-CsBatchPolicyAssignmentOperation -PolicyType TeamsAppPermissionPolicy -PolicyName $null -Identity $_.UserPrincipalName -OperationName "Batch unassign $($AppPermissionPolicy) app permission policy"
Grant-CsTeamsAppPermissionPolicy -Identity $_.UserPrincipalName -PolicyName $null
}
$GroupMembers = Get-CsOnlineUser -Filter $filter | Select UserPrincipalName
$GroupMembers | ForEach {
#New-CsBatchPolicyAssignmentOperation -PolicyType TeamsAppPermissionPolicy -PolicyName $null -Identity $_.UserPrincipalName -OperationName "Batch unassign $($AppPermissionPolicy) app permission policy"
Grant-CsTeamsAppPermissionPolicy -Identity $_.UserPrincipalName -PolicyName $null
}
#--------------------------------------------------------------------------------------#>
<# --------------------- Remove App Setup Policy from Users -----------------------------
$GroupMembers = Get-CsOnlineUser -Filter $filter | Select UserPrincipalName
$GroupMembers | ForEach {
#New-CsBatchPolicyAssignmentOperation -PolicyType TeamsAppSetupPolicy -PolicyName $null -Identity $_.UserPrincipalName -OperationName "Batch unassign $($AppPermissionPolicy) app setup policy"
Grant-CsTeamsAppSetupPolicy -Identity $_.UserPrincipalName -PolicyName $null
}
#--------------------------------------------------------------------------------------#>
Sources:
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.