Creating a new MS Teams Policy using PowerShell


In my previous blog I showed you how to obtain all the policies for users. This blog post, I’m going to show an example of how to create a new Policy for Meeting.

The script I’m providing below is a simple script that will:

  • Name the policy – Line 1
  • Import the SkypeOnlineConnector module – Line 4-7
  • Create the policy if it doesn’t exist – Lines 9 – 12
  • Set the properties of the Policy – Lines 15 – 31

This policy that is being created will prevent users of this policy creating Giphy, Memes or Stickers in their chats. (Basically, taking the fun out of teams. [insert wicked laugh])

$PolicyName = "NoGiphyOrStickersMessagePolicy"
$InformationPreference = 'Continue'
Import-Module "C:\\Program Files\\Common Files\\Skype for Business Online\\Modules\\SkypeOnlineConnector\\SkypeOnlineConnector.psd1"
$Session = New-CsOnlineSession
Import-PSSession Session:$Session AllowClobber
if (-not $(Get-CsTeamsMessagingPolicy Identity:$PolicyName ErrorAction:SilentlyContinue)) {
Write-Information MessageData:"New-CsTeamsMessagingPolicy -Identity:'$PolicyName'"
New-CsTeamsMessagingPolicy Identity:$PolicyName Description:'A policy for no Giphy Or Stickers for Messaging.'
}
Write-Information MessageData:"Set-CsTeamsMessagingPolicy -Identity:'$PolicyName'"
Set-CsTeamsMessagingPolicy Identity:$PolicyName `
AllowUrlPreviews:$true `
AllowOwnerDeleteMessage: $true `
AllowUserEditMessage: $true `
AllowUserDeleteMessage: $true `
AllowUserChat: $true `
AllowRemoveUser: $true `
AllowGiphy: $false `
GiphyRatingType: Strict `
AllowMemes: $false `
AllowImmersiveReader: $true `
AllowStickers: $false `
AllowUserTranslation: $true `
ReadReceiptsEnabledType: UserPreference `
AllowPriorityMessages: $true `
ChannelsInChatListEnabledType: DisabledUserOverride `
AudioMessageEnabledType: ChatsAndChannels `
Remove-PSSession Session:$session

As you can see from the above screen shot, I now have a policy called NoGiphyOrStickersMessagePolicy, and below is a screen shot of the settings within Teams Administration.

My previous blog showed you how to get 13 different policies for each user. Below are the links to those PowerShell Set policy commands with the different parameters.