PowerShell script sample - Create and assign a messaging policy

Use this PowerShell script to create a messaging policy in Microsoft Teams and assign it to users.

For more information about using this PowerShell script, see Quick start - Teams for Education.

If you're new to PowerShell and need help getting started, see Overview of Azure PowerShell.

Sample script

<#
.SYNOPSIS
This script creates a messaging policy in Teams and assigns it to users.
.DESCRIPTION
Use this script to create a messaging policy and assign it to users in your organization.
#>

$dataSetFilePath = "<csv file with user ids for newly provisioned students> "
 $dataSet = Import-Csv "$($dataSetFilePath)" -Header UserId –delimiter ","
 foreach($line in $dataSet)
 {
    $userId = $line.UserId
    Write-Host $userId
    Grant-CsTeamsMessagingPolicy -PolicyName "<<PolicyName for a policy created with Chat Off>>" -Identity $userId

 }