snagrat Posted January 25, 2023 Posted January 25, 2023 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?
Norphy Posted January 25, 2023 Posted January 25, 2023 Have you always been a site owner or have you just added yourself?
snagrat Posted January 25, 2023 Author Posted January 25, 2023 I wasn’t last night but added myself. Still not working this morning
Norphy Posted January 25, 2023 Posted January 25, 2023 Can you remove files in the GUI? Just as a troubleshooting step?
snagrat Posted January 25, 2023 Author Posted January 25, 2023 (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 January 25, 2023 by snagrat
Norphy Posted January 25, 2023 Posted January 25, 2023 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.
snagrat Posted January 25, 2023 Author Posted January 25, 2023 Sharepoint online. Tried both -ServerRelativeUrl and -SiteRelativeUrl as unsure if they are online/on-prem specific but both the same
Norphy Posted January 25, 2023 Posted January 25, 2023 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
snagrat Posted January 25, 2023 Author Posted January 25, 2023 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
Harbix Posted March 1, 2023 Posted March 1, 2023 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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now