Skip to content

New-MSTBatchPolicyAssignmentOperation

Teams: Create a batch policy assignment operation

#Requires -Version 5.1

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string[]]$Identities,
    [Parameter(Mandatory = $true)]
    [string]$PolicyName,
    [Parameter(Mandatory = $true)]
    [ValidateSet('CallingLineIdentity','OnlineVoiceRoutingPolicy','TeamsAppSetupPolicy','TeamsAppPermissionPolicy','TeamsCallingPolicy','TeamsCallParkPolicy','TeamsChannelsPolicy','TeamsEducationAssignmentsAppPolicy','TeamsEmergencyCallingPolicy','TeamsMeetingBroadcastPolicy','TeamsEmergencyCallRoutingPolicy','TeamsMeetingPolicy','TeamsMessagingPolicy','TeamsUpdateManagementPolicy','TeamsUpgradePolicy','TeamsVerticalPackagePolicy','TeamsVideoInteropServicePolicy','TenantDialPlan')]
    [string]$PolicyType,
    [string]$OperationName
)

Process {
    try {
        [hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'; 'Identity' = $Identities; 'PolicyName' = $PolicyName; 'PolicyType' = $PolicyType}
        if (-not [System.String]::IsNullOrWhiteSpace($OperationName)) {
            $cmdArgs.Add('OperationName', $OperationName)
        }

        $opid = New-CsBatchPolicyAssignmentOperation @cmdArgs
        $result = Get-CsBatchPolicyAssignmentOperation -OperationID $opid -ErrorAction Stop | Select-Object *

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

A list of one or more users in the tenant

The name of the policy to apply

The type of the policy

Custom name for the operation

An interactive directory of PowerShell scripts.