Skip to content

New-MSTGroupPolicyAssignment

Teams: Assign a policy to a security group or distribution list

#Requires -Version 5.1

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$GroupId,
    [Parameter(Mandatory = $true)]
    [ValidateSet('TeamsAppSetupPolicy','TeamsCallingPolicy','TeamsCallParkPolicy','TeamsChannelsPolicy','TeamsComplianceRecordingPolicy','TeamsEducationAssignmentsAppPolicy','TeamsMeetingBroadcastPolicy','TeamsMeetingPolicy','TeamsMessagingPolicy')]
    [string]$PolicyType,
    [Parameter(Mandatory = $true)]
    [string]$PolicyName,
    [int]$Rank
)

Process {
    try {
        [hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'; 'GroupId' = $GroupId; 'PolicyType' = $PolicyType; 'PolicyName' = $PolicyName}

        if ($PSBoundParameters.ContainsKey('Rank')) {
            $cmdArgs.Add('Rank', $Rank)
        }

        $result = New-CsGroupPolicyAssignment @cmdArgs | Select-Object *

        if ($null -eq $result) {
            Write-Output "Group policy assigned"
            return
        }
        $result | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format 'yyyy-MM-dd HH:mm:ss') -PassThru -Force
    }
    catch { throw }
}

Object ID of the group

The type of the policy

The name of the policy to assign

The rank of the policy assignment

An interactive directory of PowerShell scripts.