Export-Labels.ps1¶
Exports all sensitivity labels and label policies from an M365 tenant to JSON files.
Parameters¶
| Parameter | Required | Default | Description |
|---|---|---|---|
-UserPrincipalName |
Yes | — | UPN of a Compliance Administrator in the source tenant |
-OutputDir |
No | .\export |
Directory for exported JSON and log files |
Usage¶
# Default output to ./export/
.\Export-Labels.ps1 -UserPrincipalName admin@contoso.com
# Custom output directory
.\Export-Labels.ps1 -UserPrincipalName admin@contoso.com -OutputDir C:\migration\export
Output files¶
labels.json¶
Array of label objects, parents first then sub-labels, each containing:
- Identity —
DisplayName,Name,Comment,Tooltip,Priority,ContentType - Hierarchy —
ParentLabelDisplayName,_LabelPath(compound key) - Content marking — header, footer, and watermark settings
- Encryption — all encryption parameters, flagged with
_HasEncryption - AdvancedSettings — hashtable of advanced settings
- Metadata —
_SourceTenantLabelGuid,_ExportedAt
label-policies.json¶
Array of policy objects containing:
- Identity —
Name,Comment,Enabled,Priority - Label references —
LabelPathsarray with resolved compound paths - Scoping —
ExchangeLocation,ModernGroupLocationand exceptions - AdvancedSettings — hashtable of advanced policy settings
- Metadata —
_SourceTenantPolicyGuid,_ExportedAt
Behaviour¶
- Connects to the source tenant via
Connect-IPPSSession - Retrieves all labels with
Get-Label -IncludeDetailedLabelActions - Builds GUID and Name lookup tables for resolving parent labels and policy references
- Separates parent and child labels, sorts by priority
- Converts each label to a clean export object via
ConvertTo-LabelExportObject - Retrieves all policies with
Get-LabelPolicy - Resolves policy label references using both GUID and Name lookups
- Logs warnings for labels with encryption enabled