Skip to content

Instantly share code, notes, and snippets.

@jkbryan
Created March 6, 2020 17:40
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/b9f9c285fefc2ac17d3fe36f790f77cc to your computer and use it in GitHub Desktop.
Save jkbryan/b9f9c285fefc2ac17d3fe36f790f77cc to your computer and use it in GitHub Desktop.
O365 Unified Labelling - Label 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"
# Create the label
New-Label -DisplayName "My Label" -Name "My Label" -Comment "This is My Label" -Tooltip "My Label Tooltip" -AdvancedSettings @{color="#32CD32"}
# Set the properties of the label - header/ footer/ watermark and recommended conditions
Set-Label -Identity "CN=My Label,$MyTenant" -LabelActions '{"Type":"applycontentmarking","SubType":"header","Settings":[{"Key":"fontsize","Value":"10"},{"Key":"placement","Value":"Header"},{"Key":"text","Value":"HeaderText"},{"Key":"fontcolor","Value":"#000000"},{"Key":"margin","Value":"5"},{"Key":"alignment","Value":"Left"},{"Key":"disabled","Value":"false"}]}'
Set-Label -Identity "CN=My Label,$MyTenant" -LabelActions '{"Type":"applycontentmarking","SubType":"footer","Settings":[{"Key":"fontsize","Value":"10"},{"Key":"placement","Value":"Footer"},{"Key":"text","Value":"FooterText"},{"Key":"fontcolor","Value":"#000000"},{"Key":"margin","Value":"5"},{"Key":"alignment","Value":"Left"},{"Key":"disabled","Value":"false"}]}'
Set-Label -Identity "CN=My Label,$MyTenant" -LabelActions '{"Type":"applywatermarking","SubType":null,"Settings":[{"Key":"fontsize","Value":"10"},{"Key":"layout","Value":"Diagonal"},{"Key":"fontcolor","Value":"#000000"},{"Key":"disabled","Value":"false"},{"Key":"text","Value":"WatermarkText"}]}'
Set-Label -Identity "CN=My Label,$MyTenant" -Conditions '{"And":[{"Or":[{"Key":"CCSI","Value":"cb353f78-2b72-4c3c-8827-92ebe4f69fdf","Properties":null,"Settings":[{"Key":"minconfidence","Value":"75"},{"Key":"maxconfidence","Value":"100"},{"Key":"rulepackage","Value":"00000000-0000-0000-0000-000000000000"},{"Key":"mincount","Value":"1"},{"Key":"maxcount","Value":"2147483647"},{"Key":"policytip","Value":"AutoLabellingText"},{"Key":"name","Value":"ABA Routing Number"},{"Key":"groupname","Value":"Default"}]},{"Key":"CCSI","Value":"eefbb00e-8282-433c-8620-8f1da3bffdb2","Properties":null,"Settings":[{"Key":"minconfidence","Value":"75"},{"Key":"maxconfidence","Value":"100"},{"Key":"rulepackage","Value":"00000000-0000-0000-0000-000000000000"},{"Key":"mincount","Value":"1"},{"Key":"maxcount","Value":"2147483647"},{"Key":"policytip","Value":"AutoLabellingText"},{"Key":"name","Value":"Argentina National Identity (DNI) Number"},{"Key":"groupname","Value":"Default"},{"Key":"autoapplytype","Value":"Recommend"}]}]}]}'
# Check that the LabelActions and Conditions were set:
$Label=Get-Label -Identity "CN=My Label,$MyTenant"
$Label.LabelActions
$Label.Conditions
# If you want to create a sub label under "My Label":
# First get the top level label:
$MyLabel = Get-Label -Identity "CN=My Label,$MyTenant"
# Then create the new label referencing the top level label by name in the ParentId parameter:
New-Label -DisplayName "My Sub Label" -Name "My Sub Label" -ParentId $MyLabel.Name -Comment "This is My Sub Label" -Tooltip "My Sub Label Tooltip"
# 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