Skip to content

Grant-MSTUserPolicyPackage

Teams: Apply a policy package to users

#Requires -Version 5.1

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string[]]$Users,
    [Parameter(Mandatory = $true)]
    [string]$PackageName
)

Process {
    try {
        [hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'; 'PackageName' = $PackageName; 'Identity' = $Users}
        $null = Grant-CsUserPolicyPackage @cmdArgs

        $result = @()
        foreach ($usr in $Users) {
            $pkgs = Get-CsUserPolicyPackage -Identity $usr -ErrorAction Stop | Select-Object *
            $result += [PSCustomObject]@{
                Timestamp   = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
                User        = $usr
                PackageName = $PackageName
                Status      = 'Policy package applied'
            }
            if ($null -ne $pkgs) {
                $result += $pkgs
            }
        }

        Write-Output $result
    }
    catch { throw }
}

A list of one or more users in the tenant

The name of the policy package to apply

An interactive directory of PowerShell scripts.