While uploading the files in the Library error

sns 9,226 Reputation points

I am trying to use PowerShell Script to upload the files but coming up with access denied error although I am global admin and sharepoint admin and local admin.

Please see below screenshot. Please help. thanks
I tried to run ISE as admin also , but no luck

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,610 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CaseyYang-MSFT 10,321 Reputation points

    Hi @sns ,

    Please check whether this library has unique permission. And check your permission if this library has unique permission.

    Library > Library settings > Permissions for this document library


    And you could try to use following PowerShell commands:

    $SiteURL = "https://xxx.sharepoint.com/sites/xxx"  
    $FilesPath = "D:\xxx"  
    $ServerRelativePath = "/Shared Documents"  
    #Connect to PnP Online  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
    #Get All Files from a Local Folder  
    $Files = Get-ChildItem -Path $FilesPath -Force -Recurse  
    #Upload All files from the directory  
    ForEach ($File in $Files)  
        Write-host "Uploading $($File.Directory)\$($File.Name)"  
        #upload a file to sharepoint online using powershell - Upload File and Set Metadata  
        Add-PnPFile -Path "$($File.Directory)\$($File.Name)" -Folder $ServerRelativePath -Values @{"Title" = $($File.Name)}  

    For Reference: SharePoint Online: Upload Files to Document Library using PowerShell
    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.