Jump to content

Recommended Posts

Posted

I’m trying to delete files stored in a Private Channel using Powershell. The file exists, I am a Site Owner but when using Remove-PnPFile I keep getting an “Access Denied” error.

 

Anyone done this before and have any suggestions?

Posted (edited)

EDIT: I can remove via the GUI.

 

This is my command

 

Remove-PnPFile -ServerRelativeUrl "/sites/NST2-HR/Shared%20Documents/some folder/~$Copy%20of%20file.xlsx" -Force

Remove-PnPFile : Access denied.At line:1 char:1+ Remove-PnPFile -ServerRelativeUrl "/sites/NST2-HR/Shared%20Documents/ ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Remove-PnPFile], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.Files.RemoveFile

Edited by snagrat
Posted

Is this SharePoint Online or on-prem SharePoint?

 

I remember that adding files via add-pnpfile was a bit of a palaver, let me look over my notes, see what I worked out and see if that applies to removing them as well.

Posted

OK, I've tried it on my test tenant. This is the setup:

 

Site called "TestSite"

Document library in there called "Shared Documents"

XLSX file called book1.xlsx

 

First, connect to the SharePoint site:

 

connect-pnponline -url https://TENANT.sharepoint.com/sites/TestSite -Interactive

 

Then remove the file with the site relative URL:

 

Remove-PnPFile -SiteRelativeUrl "/shared documents/book1.xlsx"

 

 

So remove the /sites/etc from the url you're putting into the URL

Posted
OK, I've tried it on my test tenant. This is the setup:

 

Site called "TestSite"

Document library in there called "Shared Documents"

XLSX file called book1.xlsx

 

First, connect to the SharePoint site:

 

connect-pnponline -url https://TENANT.sharepoint.com/sites/TestSite -Interactive

 

Then remove the file with the site relative URL:

 

Remove-PnPFile -SiteRelativeUrl "/shared documents/book1.xlsx"

 

 

So remove the /sites/etc from the url you're putting into the URL

 

Got it working.

 

I was connecting to tenant-admin and also connecting to the root and not the direct site. Removing -admin and adding /sites/SiteName made it work

  • 1 month later...
Posted

I managed to delete the file from sharepoint but only when i enter the complete filename. I could not do it using wildcard, e.g Longfilename*.txt

is there a way to use wildcard to delete?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...