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.
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.
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.
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\"}]"}]}"@
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.TooltipLabelActions = $label.LabelActions}# Create a new label using the paramsNew-Label @LabelParams
Stay tuned for more label wizardry in our next blog post! 🧙♂️🔒
Thank you for reading
/Simon