Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jkbryan
Last active March 6, 2020 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkbryan/316e20171b4a619733df6718fb37e4d2 to your computer and use it in GitHub Desktop.
Save jkbryan/316e20171b4a619733df6718fb37e4d2 to your computer and use it in GitHub Desktop.
O365 Unified Labelling - Policy Creation
# Define credentials
$AdminCredentials = Get-Credential "myadmin@oholics.net"
# Create the session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $AdminCredentials -Authentication Basic -AllowRedirection
# Import the session
Import-PSSession $Session -DisableNameChecking
# Define the tenant
$MyTenant = "CN=Configuration,CN=<TenantID>.onmicrosoft.com,OU=Microsoft Exchange Hosted Organizations,DC=FFO,DC=extest,DC=microsoft,DC=com"
# Get the labels to add to the policy
$Label1=Get-Label -Identity "CN=My Label,$MyTenant"
$Label2=Get-Label -Identity "CN=My Sub Label,$MyTenant"
# Create the Label Policy
New-LabelPolicy -Name "My Label Policy" -Labels $Label1.name,$Label2.Name -ExchangeLocation "All"
# Set the advanced settings on the new policy
Set-LabelPolicy -Identity "My Label Policy" -AdvancedSettings @{EnableCustomPermissions="False"}
Set-LabelPolicy -Identity "My Label Policy" -AdvancedSettings @{AttachmentAction="Automatic"}
Set-LabelPolicy -Identity "My Label Policy" -AdvancedSettings @{HideBarByDefault="False"}
Set-LabelPolicy -Identity "My Label Policy" -AdvancedSettings @{RequireDowngradeJustification="True"}
# When you are totally finished, disconnect the session
Remove-PSSession $Session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment