--- title: "Deploy the eSHARE Classification Columns" slug: "deploy-the-eshare-classification-columns" description: "Deploy classification columns across SharePoint sites, document libraries, and OneDrive using Set-SPOClassificationColumns.ps1 with safe reports and Apply mode" tags: ["Add Columns", "SPO Columns", "Classify", "eSHARE Classify", "Classification Columns", "data classification", "Data Attributes"] updated: 2026-11-16T03:14:18Z published: 2026-11-16T03:14:18Z canonical: "docs.eshare.com/deploy-the-eshare-classification-columns" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.eshare.com/llms.txt > Use this file to discover all available pages before exploring further. # Deploy the eSHARE Classification Columns This document describes how to add the five eSHARE classification columns to every SharePoint site, document library and OneDrive in the tenant with the `Set-SPOClassificationColumns.ps1` script. SharePoint sites are done first, then OneDrive. Every run produces an Excel report first, and nothing changes until you run it again with `-Apply`. The following steps will be reviewed: - [What the Deployment Does](/collaborate/docs/deploy-the-eshare-classification-columns#what-the-deployment-does) - [Choose How to Split the Rollout](/collaborate/docs/deploy-the-eshare-classification-columns#choose-how-to-split-the-rollout) - [Save the Deployment Script](/collaborate/docs/deploy-the-eshare-classification-columns#save-the-deployment-script) - [Run the Report for SharePoint Sites](/collaborate/docs/deploy-the-eshare-classification-columns#run-the-report-for-sharepoint-sites) - [Review Conflicts](/collaborate/docs/deploy-the-eshare-classification-columns#review-conflicts) - [Apply the Columns to SharePoint Sites](/collaborate/docs/deploy-the-eshare-classification-columns#apply-the-columns-to-sharepoint-sites) - [Add the Columns to OneDrive](/collaborate/docs/deploy-the-eshare-classification-columns#add-the-columns-to-onedrive) - [Confirm the Deployment](/collaborate/docs/deploy-the-eshare-classification-columns#confirm-the-deployment) - [Deployment Script](/collaborate/docs/deploy-the-eshare-classification-columns#deployment-script) > **PREREQUISITES:** > > The person performing these steps should be a **SharePoint Administrator** using the computer and certificate set up in [Create eSHARE Classify SPO Columns Entra ID App Registration](/collaborate/docs/create-eshare-classify-spo-columns-entra-id-app-registration). Agree the [decisions before you start](/collaborate/docs/eshare-classify-overview#decisions-to-make-before-you-start), including the default site templates, before the first `-Apply`. ### **What the Deployment Does** Each run first makes sure the tenant's default site templates add the columns to new team and communication sites: it registers eSHARE defaults, or adds the eSHARE site script to your organization's own defaults (see [Add the Classification Columns to New Sites](/collaborate/docs/eshare-classification-columns-on-new-sites)). Then, for every site collection, it: 1. Creates the five site columns in the root site, with fixed names and IDs. 2. Adds them to the site's **Document** content type, so libraries created later inherit them. 3. Adds them to every visible document library in the site and its subsites, and adds **Data Sensitivity**, **Data Classification** and **Data Attributes** to each library's default view. Each OneDrive is its own site collection with a **Documents** library, and gets the same treatment. Running the script again is safe: anything already in place is reported as **OK** and left alone. It skips system libraries such as **Site Assets**, **Style Library** and **Preservation Hold Library**. ### **Choose How to Split the Rollout** SharePoint sites and OneDrive both need the columns. The script covers SharePoint sites by default, and adds every OneDrive when you include `-IncludeOneDrive`. Choose one of these approaches: | Approach | How | Suits | | --- | --- | --- | | **Sites first, then OneDrive** (*recommended*) | Follow every section below in order. Sites are done and checked before OneDrive starts. | Most organizations, especially larger ones, or where OneDrive changes need separate sign-off | | **Everything in one pass** | Add `-IncludeOneDrive` to the Report and Apply commands for SharePoint sites, then skip '**Add the Columns to OneDrive**'. | Smaller tenants that want a single change window | | **OneDrive in batches** | After the sites, run the OneDrive commands with `-SiteUrl` and a list of OneDrive addresses, e.g. one department at a time. | Organizations that roll out to user groups in stages | ### **Save the Deployment Script** 1. Go to [Deployment Script](/collaborate/docs/deploy-the-eshare-classification-columns#deployment-script) at the end of this article, expand the script block and select the copy button in the top-right corner of the code. 2. In PowerShell 7, save what you copied as **Set-SPOClassificationColumns.ps1**: ```powershell Get-Clipboard -Raw | Set-Content -Path C:\eSHARE-Classification\Set-SPOClassificationColumns.ps1 -Encoding utf8 ``` 1. Confirm the script saved correctly. This shows the script's description: ```powershell Get-Help C:\eSHARE-Classification\Set-SPOClassificationColumns.ps1 ``` ### **Run the Report for SharePoint Sites** 1. Open PowerShell 7 and run the script in Report mode: ```powershell Set-Location C:\eSHARE-Classification Import-Module PnP.PowerShell .\Set-SPOClassificationColumns.ps1 -ConfigFile .\Contoso\contoso.tenant.json ``` 1. Check the first lines of output: they show the configuration file, tenant folder and column file in use. If any is wrong, stop the script with **Ctrl+C**. 2. When the run finishes, open the report: **Contoso\SPO-Provisioning\SPO-Provisioning-contoso-[date]-[time]-Report\SPO-Provisioning.xlsx**. | Sheet | What it shows | | --- | --- | | Summary | Counts of **Planned**, **Done**, **Conflicts**, **Skipped** and **Errors**, and one '**New sites**' row per site type for the default site templates | | Actions | Every change, per site and library, with the status **Planned** (Report), **Done** (Apply) or **OK** (already in place) | | Conflicts and errors | Existing columns that need a decision, and sites the script couldn't reach | > [!WARNING] > Note: > > To try a single site first, add `-SiteUrl "https://contoso.sharepoint.com/sites/TestSite"` (*contoso.sharepoint.us in GCC High*). A single-site Apply still registers the tenant-wide default site templates. ### **Review Conflicts** A conflict is an existing column that clashes with one of the classification columns, usually one created by hand or by another tool. The Apply commands in this article give a fixed answer for each kind, so the run doesn't stop to ask: | Conflict | Answer in the Apply command | What happens | | --- | --- | --- | | A library column with the same internal name, e.g. a **DataClassification** column created on one library | `-SameNameAction Replace` | The values are backed up, the column is swapped for the standard site column, and the values are restored. Files' '**Modified**' dates don't change. | | A column with the same display name but another internal name, e.g. **Data Sensitivity** stored as **eShareLabel** | `-SameLabelAction Skip` | The library is left alone for that column, so eSHARE can't write to it there. Contact eSHARE support to resolve it. | | A site column with the right internal name but a different ID | Asked during the run | Choose '**Keep**' to use the existing site column. Nothing is deleted. | Before the script moves or deletes any value, it saves the values to a CSV file in the run's **Backups** folder. ### **Apply the Columns to SharePoint Sites** 1. Run the same command with `-Apply` and the conflict answers: ```powershell Set-Location C:\eSHARE-Classification Import-Module PnP.PowerShell .\Set-SPOClassificationColumns.ps1 -ConfigFile .\Contoso\contoso.tenant.json `    -Apply -SameNameAction Replace -SameLabelAction Skip ``` 1. Wait for the run to finish. As a guide, about 500 site collections take around 35 minutes. 2. Open the Apply report and check the '**Conflicts and errors**' sheet. Locked or read-only sites return **403 Forbidden** and are skipped. 3. Open a library and confirm that the '**Data Sensitivity**', '**Data Classification**' and '**Data Attributes**' columns are shown. ![](https://cdn.us.document360.io/c516537f-0d2f-4bf8-930d-3385ca9a11d7/Images/Documentation/CleanShot 2026-11-15 at 22.13.10@2x.png?sv=2026-02-06&spr=https&st=2026-11-18T20%3A22%3A42Z&se=2026-11-18T21%3A22%3A42Z&sr=b&sp=r&sig=vJieKbneT6A%2BSiwzl9Sy7ibeDnh3f60cUUljNrd4t5o%3D) ### **Add the Columns to OneDrive** Adding `-IncludeOneDrive` covers every OneDrive. The run also re-checks the SharePoint sites, which show as **OK**. Expect it to take longer than the sites, as each user has their own OneDrive. 1. Run the Report with `-IncludeOneDrive`: ```powershell Set-Location C:\eSHARE-Classification Import-Module PnP.PowerShell .\Set-SPOClassificationColumns.ps1 -ConfigFile .\Contoso\contoso.tenant.json -IncludeOneDrive ``` 1. Review the report as you did for the sites. 2. Run the Apply: ```powershell .\Set-SPOClassificationColumns.ps1 -ConfigFile .\Contoso\contoso.tenant.json -IncludeOneDrive `    -Apply -SameNameAction Replace -SameLabelAction Skip ``` 1. Check the '**Conflicts and errors**' sheet. Expected errors: - **403 Forbidden** on some OneDrives, e.g. those of departed users. - An **unauthorized operation** or **storage limit** error on a OneDrive that is read-only or full. 2. Sign in as a test user, open '**OneDrive**' > '**My files**', select a file and open '**Details**'. The '**Properties**' section lists '**Data Sensitivity**', '**Data Classification**' and '**Data Attributes**'. > [!WARNING] > Note: > > To roll out OneDrive in batches, add `-SiteUrl` with the OneDrive addresses to both commands, e.g. `-SiteUrl "https://contoso-my.sharepoint.com/personal/jane_contoso_com", "https://contoso-my.sharepoint.com/personal/sam_contoso_com"`. In GCC High, OneDrive addresses end in **-my.sharepoint.us**. In OneDrive, users see the classification in a file's **Details** pane and can filter by it. The newer OneDrive layout doesn't show custom columns in the file list. ### **Confirm the Deployment** 1. Run the Report again with `-IncludeOneDrive` (*without* `-Apply`). 2. In the '**Summary**' sheet, confirm that **Planned** is **0**, **Conflicts** is **0**, and the three '**New sites**' rows show **OK**. 3. If **Planned** isn't 0, check the rows in '**Actions**'. OneDrives that can be read but refuse changes always show as Planned; they match the errors from the Apply run and can be left. ### **Deployment Script** 1. Copy the script below with the copy button and save it as **C:\eSHARE-Classification\Set-SPOClassificationColumns.ps1**. Without `-Apply` it only reports; with `-Apply` it makes the changes. **Expand this block and copy the **Set-SPOClassificationColumns.ps1** script below** ```powershell <# .SYNOPSIS    Pre-creates the eSHARE classification columns (default: "Data Sensitivity" / DataSensitivity,    "Data Classification" / DataClassification, "Data Attributes" / DataAttributes,    "eSHARE_GUID" / eSHARE_GUID and "Data Sensitivity Id" / DataSensitivityId) as site columns in    every site collection, attaches them    to each site's Document content type so new libraries inherit them, and adds them to every existing    document library and its default view. Conflicting columns are reported and handled per your choice. .DESCRIPTION    Runs in two modes:      Report (default)  Read-only. Lists every change it would make and every conflict that needs a decision.      -Apply            Makes the changes. Prompts for each conflict (or uses -SameNameAction / -SameLabelAction).    Per site collection:      1. Creates each column as a site column in the root web, with a fixed GUID and the exact         internal and display names from the column definitions.      2. Adds the site columns to the root web's "Document" content type (without pushing down), so         libraries created later inherit them.      3. For every visible document library in the site and its subsites:           - adds the columns to the library and to its document content types           - adds them to the library's default view           - handles conflicts (below)    Conflicts, per library and column:      Same internal name, different column (e.g. a library-only "DataSensitivity" created earlier):        Keep     keep the existing column; make sure its display name and default view are right (suggested at the prompt)        Replace  back up values, delete the existing column, add the site column, restore values        Skip     leave the library untouched for this column      Same display name, different internal name (e.g. "Data Sensitivity" stored as eShareLabel):        Rename     rename the existing column to " ()", then add the site column (suggested at the prompt)        Migrate    add the site column, copy the existing values into it, back them up, then delete the existing column        AddAnyway  add the site column alongside; the library ends up with two columns with the same label        Skip       leave the library untouched for this column    Every value that is moved or deleted is first written to a CSV backup in the run's output folder.    Library vs default view: a column can be on the library (values stored, shown in the details pane,    used by search and DLP) without being in the library's default view (what the file list, Sort by and    the filter pane show). In the newer OneDrive web layout, sorting rewrites the default view and drops    custom columns from it; the values are not affected. For a column already on a library, the run checks    content types and default view separately: Report shows "missing from default view" as Planned, Apply    re-adds it, and a library with nothing missing is reported OK.    New sites (mandatory, every run): makes sure the tenant's default site templates for team sites (with    and without a group) and communication sites run the site script "eSHARE classification columns", built    from the column definitions, so new sites get the columns in their Documents library. Report lists what    it would register or update; Apply does it. An existing default from someone else stays the default and    gets the site script added. Results are on the console, the Actions sheet and the Summary sheet.    What this does NOT cover: libraries created later in an existing site get the columns (through the    Document content type) but not in their default view, and new OneDrives get nothing until a run with    -IncludeOneDrive. Re-run it on a schedule. .PARAMETER ConfigFile    A .tenant.json file (same format as Get-SPOColumnInventory.ps1; see example.tenant.json.sample).    With no -ConfigFile, the script looks for *.tenant.json in its own folder and in the tenant subfolders    one level down (e.g. Contoso\): one is used automatically, several give a menu.    The folder holding the chosen file is the TENANT FOLDER: column files and run output default to it.    CertificatePath: "~/" means your home folder; other relative paths are resolved against the tenant    folder. Keep the .pfx OUTSIDE the synced SharePoint folder (it holds the app's private key).    This script needs an app registration with WRITE access (SharePoint Sites.FullControl.All, application).    Put its values in the file as ProvisioningClientId plus ProvisioningCertificatePath (.pfx, any OS) or    ProvisioningCertificateThumbprint (Windows only); without ProvisioningClientId, ClientId and    CertificatePath / CertificateThumbprint are used. .PARAMETER CertificatePassword    Password of the .pfx file, as a SecureString. Only used with a CertificatePath; if omitted, the script    prompts for it (press Enter for a .pfx without a password). Never stored in the config file. .PARAMETER ColumnsFile    JSON file with the column definitions. Default: classification-columns.json in the tenant folder if    there is one, otherwise the shared classification-columns.json next to the script; if neither exists,    the built-in defaults are used and written next to the script for reference.    Each entry: InternalName, DisplayName, Id, Type (Text), Group, and optionally "AddToDefaultView": false    to keep the column off the default view (it is still added to libraries and content types, shown in the    details pane and indexed by search; it is never removed from a view someone added it to).    A relative -ColumnsFile is looked up in the tenant folder, then the current folder, then the script    folder. A file passed with -ColumnsFile must exist; otherwise the script stops. .PARAMETER SiteUrl    Limit the run to one or more site collection URLs. Recommended for the first run. .PARAMETER Apply    Make the changes. Without -Apply the script runs in Report mode: it reads the tenant, writes the    Excel report of everything it would do, and changes nothing. Always run without -Apply first. .PARAMETER SiteColumnAction    What to do when a site already has a SITE column with the right internal name but a different ID    (e.g. created by another script or by hand, so not the fixed ID from the column definitions).      Prompt   ask for each site during -Apply; in Report mode the conflict is listed for a decision (default)      Keep     adopt the existing site column (Text columns only): fix its display name if needed, link it to               the Document content type, and use it for the libraries and default views. Nothing is deleted               and no values move. Search and DLP work the same: the managed property (DataClassificationOWSTEXT)               comes from the internal name, not the ID.      Skip     leave the column alone on that site (the previous behaviour)    A site column of another type (not Text) is always reported as a conflict and skipped. .PARAMETER SameNameAction    What to do when a library already has a different column with the same INTERNAL name    (e.g. a library-only "DataSensitivity" created by hand before the site column existed).      Prompt   ask for each conflict during -Apply; in Report mode the conflict is listed for a decision (default)      Keep     keep the existing column; correct its display name and add it to the default view      Replace  back up its values, delete it, add the site column, then restore the values      Skip     leave that library alone for this column .PARAMETER SameLabelAction    What to do when a library already has a different column with the same DISPLAY name but another    internal name (e.g. "Data Classification" stored as eShareGUID).      Prompt     ask for each conflict during -Apply; in Report mode the conflict is listed for a decision (default)      Rename     rename the existing column to " ()", then add the site column.                 Nothing is deleted and no values move; the existing column keeps its internal name.      Migrate    add the site column, copy the existing values into it, then delete the existing column.                 Values are backed up to CSV first. Only Text, Note (multi-line) and Choice columns are migrated;                 other types are skipped and reported.      AddAnyway  add the site column next to the existing one; the library ends up with two columns that                 show the same label      Skip       leave that library alone for this column    At a prompt you can apply the same answer to all remaining conflicts of that kind. .PARAMETER ExcludeLibrary    Document library titles to leave alone. Default: Style Library, Site Assets, Form Templates,    Preservation Hold Library, Site Collection Documents, Site Collection Images, Teams Wiki Data.    Passing a value REPLACES the default list, so include the defaults you still want excluded.    Hidden libraries are always skipped. .PARAMETER IncludeOneDrive    Also process OneDrive (personal, -my) sites. Off by default. .PARAMETER OutputFolder    Parent folder for the run output. Each run creates    SPO-Provisioning--- inside it, containing SPO-Provisioning.xlsx    and a Backups folder. Default: SPO-Provisioning in the tenant folder. .EXAMPLE    .\Set-SPOClassificationColumns.ps1 -SiteUrl "https://contoso.sharepoint.com/sites/Test"    Report only, one site. Picks the tenant from the *.tenant.json files in the tenant subfolders (menu if several). .EXAMPLE    .\Set-SPOClassificationColumns.ps1 -ConfigFile .\Contoso\contoso.tenant.json -ColumnsFile extra-column.json    Report only, whole tenant, using a column file from the Contoso tenant folder. .EXAMPLE    .\Set-SPOClassificationColumns.ps1 -SiteUrl "https://contoso.sharepoint.com/sites/Test" -Apply    Make the changes on one site, prompting for each conflict. .EXAMPLE    .\Set-SPOClassificationColumns.ps1 -Apply -SameNameAction Keep -SameLabelAction Skip    Whole tenant, unattended (e.g. scheduled), with fixed conflict decisions. .NOTES    Requires PowerShell 7.4+, PnP.PowerShell, ImportExcel. Runs on Windows, macOS and Linux; on macOS and    Linux the certificate must be a .pfx file (CertificatePath), because thumbprints need the Windows store.    App registration (separate from the read-only inventory app): SharePoint API > Application permission    Sites.FullControl.All, admin consent, certificate uploaded. #> [CmdletBinding()] param(    [string]$ConfigFile,    [string]$ColumnsFile,    [string[]]$SiteUrl,    [switch]$Apply,    [ValidateSet('Prompt', 'Keep', 'Skip')]    [string]$SiteColumnAction = 'Prompt',    [ValidateSet('Prompt', 'Keep', 'Replace', 'Skip')]    [string]$SameNameAction = 'Prompt',    [ValidateSet('Prompt', 'Rename', 'Migrate', 'AddAnyway', 'Skip')]    [string]$SameLabelAction = 'Prompt',    [string[]]$ExcludeLibrary = @('Style Library', 'Site Assets', 'Form Templates', 'Preservation Hold Library',                                  'Site Collection Documents', 'Site Collection Images', 'Teams Wiki Data'),    [switch]$IncludeOneDrive,    [string]$OutputFolder,    [SecureString]$CertificatePassword ) $ErrorActionPreference = 'Stop' # ---------- Tenant config ---------- # Folder layout: the scripts sit at the root; each tenant has its own subfolder holding .tenant.json, # any tenant-specific column files, its certificate (.pfx, optional) and its run output. if (-not $ConfigFile) {    $found = @(Get-ChildItem -Path $PSScriptRoot -Filter '*.tenant.json' -File -Recurse -Depth 1 -ErrorAction SilentlyContinue | Sort-Object FullName)    if ($found.Count -eq 1) { $ConfigFile = $found[0].FullName }    elseif ($found.Count -gt 1) {        Write-Host "Tenant config files found:" -ForegroundColor Cyan        for ($k = 0; $k -lt $found.Count; $k++) { Write-Host ("  [{0}] {1}" -f ($k + 1), [System.IO.Path]::GetRelativePath($PSScriptRoot, $found[$k].FullName)) }        $pick = Read-Host "Select a tenant (1-$($found.Count))"        if ($pick -notmatch '^\d+$' -or [int]$pick -lt 1 -or [int]$pick -gt $found.Count) { throw "Invalid selection '$pick'." }        $ConfigFile = $found[[int]$pick - 1].FullName    } else { throw "No *.tenant.json file found in the script folder or its tenant subfolders. Create one from example.tenant.json.sample." } } $hit = @($ConfigFile, (Join-Path $PSScriptRoot $ConfigFile)) | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1 if (-not $hit) { throw "Tenant config not found: $ConfigFile" } $ConfigFile   = (Resolve-Path -LiteralPath $hit).Path $TenantFolder = Split-Path -Parent $ConfigFile $cfg = Get-Content -LiteralPath $ConfigFile -Raw | ConvertFrom-Json Write-Host "Using tenant config: $ConfigFile" -ForegroundColor Cyan Write-Host "Tenant folder:       $TenantFolder" -ForegroundColor Gray $Cloud = if ($cfg.Cloud) { [string]$cfg.Cloud } else { 'Commercial' } $cloudSettings = @{    Commercial = @{ PnPEnv = 'Production';       SpoDomain = 'sharepoint.com';    InitialDomain = 'onmicrosoft.com' }    GCC        = @{ PnPEnv = 'Production';       SpoDomain = 'sharepoint.com';    InitialDomain = 'onmicrosoft.com' }    GCCHigh    = @{ PnPEnv = 'USGovernmentHigh'; SpoDomain = 'sharepoint.us';     InitialDomain = 'onmicrosoft.us' }    DoD        = @{ PnPEnv = 'USGovernmentDoD';  SpoDomain = 'sharepoint-mil.us'; InitialDomain = 'onmicrosoft.us' } }[$Cloud] if (-not $cloudSettings) { throw "Unknown Cloud '$Cloud' in $ConfigFile." } $TenantName = [string]$cfg.TenantName if (-not $TenantName) { throw "TenantName is missing from $ConfigFile." } $TenantId   = if ($cfg.TenantId) { [string]$cfg.TenantId } else { "$TenantName.$($cloudSettings.InitialDomain)" } $AdminUrl   = if ($cfg.AdminUrl) { [string]$cfg.AdminUrl } else { "https://$TenantName-admin.$($cloudSettings.SpoDomain)" } # Write-access app: the Provisioning* keys when ProvisioningClientId is set, otherwise the general keys. $pfx = if ($cfg.ProvisioningClientId) { 'Provisioning' } else { '' } if (-not $pfx) {    Write-Warning "No ProvisioningClientId in the config; using ClientId. That app needs the SharePoint Sites.FullControl.All application permission." } $ClientId = [string]$cfg."${pfx}ClientId" if (-not $ClientId) { throw "${pfx}ClientId is missing from $ConfigFile." } # Certificate: a .pfx file (any OS) or a thumbprint in the Windows certificate store (Windows only). function Get-CertificateAuth([string]$Path, [string]$Thumb, [string]$KeyPrefix) {    if ($Path) {        if ($Path -match '^~[\\/]') { $Path = Join-Path $HOME $Path.Substring(2) }        if (-not [System.IO.Path]::IsPathRooted($Path)) { $Path = Join-Path $TenantFolder $Path }        if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) { throw "Certificate file not found: $Path" }        $pw = if ($CertificatePassword) { $CertificatePassword } else { Read-Host "Password for certificate $(Split-Path $Path -Leaf) (press Enter if none)" -AsSecureString }        return @{ CertificatePath = $Path; CertificatePassword = $pw }    }    if ($Thumb) {        if (-not $IsWindows) { throw "${KeyPrefix}CertificateThumbprint works only on Windows (certificate store). On macOS or Linux, set ${KeyPrefix}CertificatePath to a .pfx file in $ConfigFile." }        return @{ Thumbprint = $Thumb }    }    throw "No certificate in ${ConfigFile}: set ${KeyPrefix}CertificatePath (.pfx, any OS) or ${KeyPrefix}CertificateThumbprint (Windows)." } $auth = @{ ClientId = $ClientId; Tenant = $TenantId; AzureEnvironment = $cloudSettings.PnPEnv } +        (Get-CertificateAuth ([string]$cfg."${pfx}CertificatePath") ([string]$cfg."${pfx}CertificateThumbprint") $pfx) if (-not $OutputFolder) { $OutputFolder = Join-Path $TenantFolder 'SPO-Provisioning' } # ---------- Column definitions ---------- $defaultColumns = @(    [pscustomobject]@{ InternalName = 'DataSensitivity';    DisplayName = 'Data Sensitivity';    Id = 'bcd76661-7896-4c3d-bc54-ecea10b0c89b'; Type = 'Text'; Group = 'eSHARE Classification' }    [pscustomobject]@{ InternalName = 'DataClassification'; DisplayName = 'Data Classification'; Id = 'bca4e5cd-33a5-4e46-be56-8095e47e0e05'; Type = 'Text'; Group = 'eSHARE Classification' }    [pscustomobject]@{ InternalName = 'DataAttributes';     DisplayName = 'Data Attributes';     Id = 'ab608904-89f8-41ab-a9b6-3baa23d8301e'; Type = 'Text'; Group = 'eSHARE Classification' }    [pscustomobject]@{ InternalName = 'eSHARE_GUID';        DisplayName = 'eSHARE_GUID'; Id = '2b9f22d9-7146-4256-8ed4-e9af0ff626c4'; Type = 'Text'; Group = 'eSHARE Classification'; AddToDefaultView = $false }    [pscustomobject]@{ InternalName = 'DataSensitivityId';  DisplayName = 'Data Sensitivity Id'; Id = '266c9095-8a61-43be-a51b-d64626750588'; Type = 'Text'; Group = 'eSHARE Classification'; AddToDefaultView = $false } ) if ($ColumnsFile) {    $cands = if ([System.IO.Path]::IsPathRooted($ColumnsFile)) { @($ColumnsFile) } else {        @((Join-Path $TenantFolder $ColumnsFile), $ColumnsFile, (Join-Path $PSScriptRoot $ColumnsFile)) }    $hit = $cands | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1    if (-not $hit) { throw "Columns file '$ColumnsFile' not found (looked in $TenantFolder, the current folder and $PSScriptRoot)." }    $ColumnsFile = (Resolve-Path -LiteralPath $hit).Path } else {    $tenantCols = Join-Path $TenantFolder 'classification-columns.json'    $ColumnsFile = if (Test-Path -LiteralPath $tenantCols -PathType Leaf) { $tenantCols } else { Join-Path $PSScriptRoot 'classification-columns.json' } } if (Test-Path -LiteralPath $ColumnsFile) {    $columns = @(Get-Content -LiteralPath $ColumnsFile -Raw | ConvertFrom-Json) } else {    $columns = $defaultColumns    $columns | ConvertTo-Json | Out-File -FilePath $ColumnsFile -Encoding utf8    Write-Host "Wrote default column definitions to $ColumnsFile" -ForegroundColor Gray } foreach ($c in $columns) {    if ($c.InternalName -notmatch '^[A-Za-z][A-Za-z0-9_]*$') { throw "Internal name '$($c.InternalName)' must be letters, digits and underscores only (no spaces)." }    if ($c.Type -ne 'Text') { throw "Column '$($c.InternalName)': only Type 'Text' is supported." } } function Get-FieldXml($c) {    $dn = [System.Security.SecurityElement]::Escape($c.DisplayName)    $gr = [System.Security.SecurityElement]::Escape($c.Group)    "" } # ---------- Output and logging ---------- $OutputFolder = Join-Path (New-Item -ItemType Directory -Path $OutputFolder -Force).FullName `    ("SPO-Provisioning-$TenantName-" + (Get-Date -Format 'yyyyMMdd-HHmm') + $(if ($Apply) { '-Apply' } else { '-Report' })) New-Item -ItemType Directory -Path (Join-Path $OutputFolder 'Backups') -Force | Out-Null $log = [System.Collections.Generic.List[object]]::new() function Write-Log($Site, $Web, $Library, $Column, $Action, $Result, $Detail) {    $log.Add([pscustomobject]@{ Site = $Site; Web = $Web; Library = $Library; Column = $Column                                Action = $Action; Result = $Result; Detail = $Detail })    $color = switch ($Result) { 'Done' { 'Green' } 'Planned' { 'Gray' } 'Conflict' { 'Yellow' } 'Skipped' { 'DarkYellow' } 'Error' { 'Red' } default { 'White' } }    Write-Host ("    {0,-22} {1,-9} {2} {3}" -f $Action, $Result, $(if ($Library) { "[$Library]" }), "$Column $Detail") -ForegroundColor $color } # ---------- Conflict decisions ---------- $remembered = @{} function Get-Decision([string]$Kind, [string]$Fixed, [string]$Question, [System.Collections.Specialized.OrderedDictionary]$Options, [string]$Default) {    if ($Fixed -ne 'Prompt') { return $Fixed }    if ($remembered.ContainsKey($Kind)) { return $remembered[$Kind] }    if (-not $Apply) { return 'Decide' }    Write-Host ""    Write-Host "  CONFLICT: $Question" -ForegroundColor Yellow    $keys = @($Options.Keys)    for ($k = 0; $k -lt $keys.Count; $k++) {        $mark = if ($keys[$k] -eq $Default) { ' (default)' } else { '' }        Write-Host ("    [{0}] {1,-10} {2}{3}" -f ($k + 1), $keys[$k], $Options[$keys[$k]], $mark)    }    do {        $ans = Read-Host "  Choose 1-$($keys.Count), Enter for default"        if (-not $ans) { $choice = $Default; break }        if ($ans -match '^\d+$' -and [int]$ans -ge 1 -and [int]$ans -le $keys.Count) { $choice = $keys[[int]$ans - 1]; break }        Write-Host "  Not a valid choice." -ForegroundColor Red    } while ($true)    $all = Read-Host "  Use '$choice' for all remaining conflicts of this kind? (y/N)"    if ($all -match '^[Yy]') { $remembered[$Kind] = $choice }    return $choice } $siteColumnOptions = [ordered]@{    Keep = 'Adopt the existing site column (keep its ID); link it and use it for libraries and views'    Skip = 'Leave this column alone on this site' } $sameNameOptions = [ordered]@{    Keep    = 'Keep the existing column; fix its display name and add it to the default view'    Replace = 'Back up values, delete the existing column, add the site column, restore values'    Skip    = 'Leave this library unchanged for this column' } $sameLabelOptions = [ordered]@{    Rename    = 'Rename the existing column to "