Skip to content

Instantly share code, notes, and snippets.

# Alexander Holmeset
# Version 1.0
# This script is designed to extract sensitivity labels from files in SharePoint document libraries in one tenant and apply them to the same files in another tenant.
# It uses Microsoft Graph API to interact with SharePoint and sensitivity labels.
# The script connects to two different tenants using app registrations and retrieves files from SharePoint document libraries.
# App regstiration permissions source: Directory.Read.All, Files.Read.All, Sites.Read.All and InformationProtectionPolicy.Read.All
# App regstiration permissions target: Directory.Read.All, Files.ReadWrite.All, Sites.Read.All and InformationProtectionPolicy.Read.All
# Parameters for the app registration source tenant
$ClientId = "xxxxxxx"
# Parameters for the app registration
$ClientId = "xxxxx"
$TenantId = "xxxxx"
$ClientSecret = "xxxxx"
$NumberOfMajorVersionsToKeep = 20
$TotalSizeAllVersions = 0
$TotalSizeReducedVersions = 0
#Threshold for the last activity
$threshold = 50
$CopilotLicenseGroupID = "xxxxx-xxx-xxxx-xxx"
# Connect to Microsoft Graph using the Tenant ID and Client Secret Credential
Connect-MgGraph -identity
#Requires -Modules Microsoft.Graph
# Install the module. (You need admin on the machine.)
# Install-Module Microsoft.Graph
# Set Static Variables
$TenantID="Enter your Tenant ID"
$LogicAppDisplayname = "CopilotActivityCheck"
# Define dynamic variables
$ServicePrincipalFilter = "displayName eq '$($LogicAppDisplayname)'"
#Requires -Modules Microsoft.Graph
# Install the module. (You need admin on the machine.)
# Install-Module Microsoft.Graph
# Set Static Variables
$TenantID="Enter your Tenant ID"
$LogicAppDisplayname = "NewCopilotUserEmail"
# Define dynamic variables
$ServicePrincipalFilter = "displayName eq '$($LogicAppDisplayname)'"
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"triggers": {
"Recurrence": {
"type": "Recurrence",
"recurrence": {
"interval": 3,
"frequency": "Month",
{"text":"Hello World"}
# Parameters for the app registration
$ClientId = "XXXXXXXXXXXX"
$TenantId = "XXXXXXXXXXXX"
$ClientSecret = "XXXXXXXXXXXX"
# Convert the Client Secret to a SecureString
$SecureClientSecret = ConvertTo-SecureString -String $ClientSecret -AsPlainText -Force
# Create a PSCredential object with the Client ID and Secure Client Secret
$ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ClientId, $SecureClientSecret
base64ToBinary(variables('audiostring'))
outputs('http_3')?['body/$content']