Remove-PnPFolder Error On Version 1.10.0 #1755
Unanswered
The-Phantom10
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Having an issue where I'm getting the following error code when running Remove-PnPFolder, the Remove-PnPFile works fine:
'Remove-PnPFolder : Server relative urls must start with SPWeb.ServerRelativeUrl'
I saw this online and people suggested making sure the / is in the file path but that hasn't made a difference.
Tried two different variations of the script but it always fails on removing the folders, files works fine. The code below looks at the file in C:\Users\Blah\Documents\Scripts\Folder.txt which contains 'Shared Documents/General/Test'
`function DeleteSharePointFileAndFolders($Fol){
$allNestedFiles = Get-PnPFolderItem -FolderSiteRelativeUrl $Fol -ItemType File
$allNestedFolders = Get-PnPFolderItem -FolderSiteRelativeUrl $Fol -ItemType Folder
$removeServerRelativeURL = $folder.ServerRelativeUrl.Replace($folder.Context.web.ServerRelativeURL,"")
DeleteSharePointFileAndFolders -Fol $removeServerRelativeURL
Remove-PnPFolder -Name $folder.Name -Folder $addFwSlash -Force
}
Import-Module PnP.Powershell
Connect-PnPOnline -Url "https://test.sharepoint.com/teams/BlabBlah" -Interactive
#This is where the logs of deleted files and folders will be saved
$logs = "C:\Scripts\DeleteFoldersSubfoldersAndFiles\logs.txt"
#Create a directory in your onedrive documents called Scripts (C:\Users\Blah\Documents\Scripts) and place the Folders.txt in there. Folders.txt is where you supply the location to delete eg Shared Documents/General/Test
$folfiles = get-content "C:\Users\Blah\Documents\Scripts\Folder.txt"
foreach($fol in $folfiles){
DeleteSharePointFileAndFolders -Fol $fol
}
`
Any help anyone can give it would be really appreciated as this one has been bugging me.
Beta Was this translation helpful? Give feedback.
All reactions