Forum Discussion

kcelmer's avatar
kcelmer
Brass Contributor
Dec 15, 2025

Error trying to Connect-PnPOnline

Hi!

I'm using PowerShell in VSC to run the following script:

# Install PnP PowerShell module if not already installed
# Install-Module PnP.PowerShell -Force

# Define SharePoint site URL, folder path, and the sensitivity label to apply
$SiteUrl = "https://yourtenant.sharepoint.com/sites/yoursite"
$FolderPath = "Shared Documents/YourFolder" # Example: "Documents/ConfidentialData"
$SensitivityLabelId = "YourSensitivityLabelId" # The GUID of your sensitivity label

# Connect to SharePoint Online
Connect-PnPOnline -Url $SiteUrl -UseWebLogin # This will open a browser for authentication

# Get all files in the specified folder
$Files = Get-PnPListItem -List "Documents" -Folder $FolderPath | Where-Object { $_.FileSystemObjectType -eq "File" }

# Loop through each file and apply the sensitivity label
foreach ($File in $Files) {
    Write-Host "Applying label to: $($File.FieldValues.FileRef)"
    Set-PnPSensitivityLabel -ListItem $File -SensitivityLabelId $SensitivityLabelId
}

Write-Host "Sensitivity label application complete."

 

I keep getting this error, "OperationStopped: Unable to load DLL 'msalruntime' or one of its dependencies: The specified module could not be found. (0x8007007E) See https://aka.ms/msal-net-wam#troubleshooting"

 

I'm using:  ExchangeOnlineManagement version 3.9.0

                  PnP.Powershell version 3.1.0

                  VSC version 1.107

                  PowerShell version 7.5.3.0

I've tried changing Connect-PnpOnline from "UseWebLogin" to "Interactive" (that asks for an Entra ID App Reg and says it's not supported).  

Any idea where this going wrong?

No RepliesBe the first to reply

Resources