PowerShell 腳本範例 - 建立及指派訊息原則

使用此 PowerShell 腳本在 Microsoft Teams 中建立訊息原則,並將它指派給使用者。

如需使用此 PowerShell 腳本的詳細資訊,請參閱快速入門 - Teams 教育版

此腳本使用 商務用 Skype Online PowerShell 模組中的 Grant-CsTeamsMessagingPolicy Cmdlet。 若要深入瞭解如何使用PowerShell管理Teams,請參閱 Teams PowerShell概觀

開始之前

下載並安裝 商務用 Skype Online PowerShell 模組,然後在出現提示時重新啟動電腦。

若要深入瞭解,請參閱使用 Office 365 PowerShell 管理 商務用 Skype Online

範例腳本

<#
.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

 }

注意事項

您也可以透過批處理原則指派或使用者為其成員的群組,以縮放比例直接指派訊息原則給使用者。 如需詳細資訊,請參閱 指派原則給學校中的大型使用者群 組和 在 Teams 中指派原則給使用者