Assign policies in Microsoft Teams – the easy way

The challenge

Assigning policies in Teams or SfB Online can be a tough task when you are not using the global policy for all of your users. We had our challenges again last week to assign multiple policies to around 17.000 users. Even if you tranche your users and are using a session timer to re-connect the SfB Online Powershell it takes a long time until you have finished all your users. We even found ourselves in a situation were could not connect any SfBO Powershell or our sessions we massively throttled.

If you are looking for some guidance on how to optimize your batch processing here are some links that helped us:

Mark Vale has a blog post about tranching users for batch processing: https://commsverse.blog/2020/03/04/tranching-users-ready-for-your-microsoft-teams-migration/

Lee Ford has a nice concept of a session timer in his script: https://www.lee-ford.co.uk/get-cssessions-skype-online/

A Microsoft employee also has some helpful scripts to create robust cloud commands: https://www.powershellgallery.com/packages/HAWK/1.2.1/Content/Start-RobustCloudCommand.ps1

Batch Policy Assignment

When we prepared this change, I was hoping we haven’t to go down that route, because I read on Twitter that we will soon get some batch assignment of users in Teams. A college (Thomas Galland) tested this upfront and it was not working yet. Today he noticed it started to work and thanks to him we had an early closing time. So for those who have been waiting for this – It’s finally there and working (at least in our tenant).

New-CsBatchPolicyAssignmentOperation

The documentation can be found here:

https://docs.microsoft.com/en-us/microsoftteams/assign-policies#assign-a-policy-to-a-batch-of-users

https://docs.microsoft.com/en-us/powershell/module/teams/new-csbatchpolicyassignmentoperation?view=teams-ps

https://docs.microsoft.com/en-us/powershell/module/teams/get-csbatchpolicyassignmentoperation?view=teams-ps

What does it do?

You can now submit bulk assignment jobs directly to Teams without having a script and watch progress bars for hours.

What do you need?

The preview module of Microsoft Teams.

As of today (23.03.2020) it has version 1.0.21 and is still in preview but it worked for us very well.

Here is the guide on how to install it:

Register-PSRepository -SourceLocation https://www.poshtestgallery.com/api/v2 -Name PsTestGallery -InstallationPolicy Trusted

Uninstall-Module MicrosoftTeams -AllVersions

Install-Module MicrosoftTeams -Repository PSTestGallery

https://docs.microsoft.com/en-us/microsoftteams/assign-policies#install-and-connect-to-the-microsoft-teams-powershell-module-1

How can I create a batch job?

$user_ids = Get-Content .\users_ids.txt

New-CsBatchPolicyAssignmentOperation -PolicyType TeamsMeetingPolicy -PolicyName "CC-Default" -User $user_ids -OperationName "Update Meeting Policy – Ludicrous style"

The users must be in a proper format. No headlines, One user per line, No quotation marks.

You can specify users by their object Id, UPN, SIP address or email address. I used the SIP address.

We haven’t tested yet the variant to get users directly via Azure AD PowerShell module.

The only caveat is that only certain policy types are allowed. Don’t panic it’s 18 of them. Check if your required policy is mentioned here: https://docs.microsoft.com/en-us/powershell/module/teams/new-csbatchpolicyassignmentoperation?view=teams-ps

Microsoft says you can create batches of 20.000 users. For now, they are recommending batches of 5.000 users.

If you created your job you get an ID that you can use to view the status of your job. It can take a minute or two until you see the job. The progress is updated approximately every 30 seconds.

You can also check details about the errors:

Get-CsBatchPolicyAssignmentOperation -OperationId 0054ed9d-00f6-4a19-8c98-c8b46e115bf6 | Select -ExpandProperty UserState

You will be impressed by how fast your job is done. It’s now minutes and not hours.

There is more. You can also assign policies based on groups. This can be found here but we haven’t tested this yet:

https://docs.microsoft.com/en-us/microsoftteams/assign-policies#assign-a-policy-to-a-group

https://docs.microsoft.com/de-de/powershell/module/teams/new-csgrouppolicyassignment?view=teams-ps

I hope you find this post helpful. Happy batching.

Leave a Reply