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?

2 Replies

  • Hi kcelmer​, is this issue resolved or still persists?

    In case you are still facing this issue, here is my take. It looks like PowerShell can’t load the msalruntime DLL that modern authentication needs, so Connect-PnPOnline -UseWebLogin is failing in your PowerShell 7 + VS Code environment.

    A couple of simple options you can try:

    1. Run the same script from Windows PowerShell 5.1 (with PnP.PowerShell installed), where this usually works fine.
    2. Instead of -UseWebLogin, create an Entra ID app registration and use app-only authentication (certificate or client secret) with Connect-PnPOnline, which avoids the WAM/MSAL interactive dependency completely.

     

    • kcelmer's avatar
      kcelmer
      Brass Contributor

      Thank you DevJelly!

      I did eventually create an Entra ID app and it works. It had never done that before, so I was reluctant, but it turned out to be pretty easy. 

      Thanks!

Resources