HomeAbout Me
Microsoft 365
Advanced item sensitivity labels in PowerShell - Part 2
Simon Ågren
Simon Ågren
June 15, 2023
1 min

Table Of Contents

01
Reusing internal properties
02
Get the Label and Essential Properties
03
Cleaning Up Encryption Settings
04
Create Your Custom Label
Advanced item sensitivity labels in PowerShell - Part 2

In our journey to master sensitivity labels, we’ve already covered the basics. Now, let’s take a shortcut—a clever one. Imagine creating a label through the UI, tweaking it to perfection, and then reusing some of its hidden properties. It’s like finding a secret passage in a labyrinth—efficient and effective.

Reusing internal properties

Microsoft has marked certain properties as internal usage only. These properties hold the magic we need for advanced features like encryption and content marking. They’re like the secret sauce that makes your label truly powerful.

Get the Label and Essential Properties

Let’s start by retrieving an existing label and extracting the properties we need. In PowerShell, we can do this:

$label = Get-Label Internal -IncludeDetailedLabelActions $true | Format-List

You can always peek into $label to see what’s cooking.

Cleaning Up Encryption Settings

The label’s LabelActions[0] contains compressed JSON that we need to clean a little. I usually just copy the JSON to VS Code and format.

Remove the templateId and linkedTemplateId key-value pairs, because these are unique identifiers associated with a specific sensitivity label.

Next, replace the value with the cleaned string:

$label.LabelActions[0] = @"
{
"Type": "encrypt",
"SubType": null,
"Settings": [
{
"Key": "protectiontype",
"Value": "template"
},
{
"Key": "disabled",
"Value": "false"
},
{
"Key": "templatearchived",
"Value": "False"
},
{
"Key": "contentexpiredondateindaysornever",
"Value": "Never"
},
{
"Key": "offlineaccessdays",
"Value": "30"
},
{
"Key": "rightsdefinitions",
"Value": "[{\"Identity\":\"kingofthenorth.onmicrosoft.com\",\"Rights\":\"VIEW,VIEWRIGHTSDATA,DOCEDIT,EDIT,PRINT,EXTRACT,REPLY,REPLYALL,FORWARD,OBJMODEL\"}]"
}
]
}
"@

Create Your Custom Label

Finally, let’s put all the pieces together. Create an object with the values and forge your own label:

# Prepare the label params
$LabelParams = @{
Name = "NewLabel"
DisplayName = "NewLabel"
Tooltip = $label.Tooltip
LabelActions = $label.LabelActions
}
# Create a new label using the params
New-Label @LabelParams

Stay tuned for more label wizardry in our next blog post! 🧙‍♂️🔒

Thank you for reading
/Simon


Tags

purviewpowershell
Previous Article
Advanced item sensitivity labels in PowerShell

Simon Ågren

CTA & Microsoft MVP

Solving business problems with tech

Expertise

Microsoft 365
Azure

Social Media

githubtwitterwebsite

Related Posts

Unveiling the Truth - Custom Sensitivity Label Colors
Unveiling the Truth - Custom Sensitivity Label Colors
March 01, 2024
2 min

Quick Links

About

Social Media