Forum Discussion

ChalaC's avatar
ChalaC
Copper Contributor
Apr 05, 2020

Delete Specific file in Sharepoint Library folder

Dear All,
 
I'm looking for some help on following commands. I tried to delete on files which is in Documents Library. Im using below commands. 
 
$siteurl="https://domain.sharepoint.com/sites/test/Shared Documents"
Connect-PnPOnline -Url $siteurl
Remove-PnPFile -ServerRelativeUrl "/sites/Test/SharedDocuments/Create.csv"
 
But when it run it gives below error : 
Remove-PnPFile : The remote server returned an error: (403) Forbidden.
At line:1 char:1
+ Remove-PnPFile -ServerRelativeUrl "/sites/Test/Shared Documents/C
 
I tried several suggestions on some blogs for past few days. Still I couldn't figure out what is the issue.
Could you please some one help me on this.
Thank you.
 
 

3 Replies

  • Sudharsan K's avatar
    Sudharsan K
    Iron Contributor
    Hi,
    Based on the error, it clearly shows the account you are running the PowerShell doesn't have access rights to delete the file. It can be due to following
    1. Maybe the file is checked-out by the other user
    2. Maybe the delete action is blocked for the user
    You can check the above scenario and try deleting again or you can use -Force in your command.

    Hope it helps, please like it or mark it as a solution if it resolves ur clarification or issue
    -Sudharsan K...
    • ChalaC's avatar
      ChalaC
      Copper Contributor

      Sudharsan K I checked with mentioned suggestions. Still I getting the same error. I Can delete the file without issues from GUI using the same user. 

       

      Also the -Force also giving same error. 

    • ChalaC's avatar
      ChalaC
      Copper Contributor

      Sudharsan K Thank you for your valuable inputs. The user has owner permission for the site. 

      I will check as you described and share the output.

       

      Thanks again. 

Resources