SharePoint (2003 thru Online): Sensitivity labels Properties of all files in a Document library

Thursday, June 20, 2024

Sensitivity labels Properties of all files in a Document library

Copilot is a big deal on Microsoft 365 these days. Lots of people are using it, and Sensitivity labels are getting more popular too. I had to run a PowerShell Script to get the Properties of all files in a Document library, including their Sensitivity labels. PnP PowerShell made it easy for me.

I ran the script using the PowerShell extension in Visual Studio Code.

# Connect to the SharePoint site
$siteURL = "https://gurram.sharepoint.com/sites/dev"
Connect-PnPOnline -Url $siteURL -Interactive

# The name of the document library
$libraryName = "test1"

# Retrieve all list items in the document library
$items = Get-PnPListItem -List $libraryName

# Loop through each item and retrieve FieldValuesForEdit
foreach ($item in $items) {
    # Retrieve the FieldValuesForEdit property of the list item
    $fieldValuesForEdit = Get-PnPProperty -ClientObject $item -Property "FieldValuesForEdit"
    Write-Host "Item ID:" $item.Id
    Write-Host "FieldValuesForEdit:"
    $fieldValuesForEdit.FieldValues.FileRef #FileReferenceLink
    $fieldValuesForEdit.FieldValues._IpLabelId #Label ID
    $fieldValuesForEdit.FieldValues._DisplayName #Label Display Name
}

Below screenshot shows the result.


No comments:

Post a Comment