Copying contents of Sharepoint folder (but not actual folder) up a directory in the same site

%3CLINGO-SUB%20id%3D%22lingo-sub-1977340%22%20slang%3D%22en-US%22%3ECopying%20contents%20of%20Sharepoint%20folder%20(but%20not%20actual%20folder)%20up%20a%20directory%20in%20the%20same%20site%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1977340%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20attempting%20to%20remove%20some%20unnecessary%20parents%20folders%20from%20our%20Sharepoint%20Online%20sites%20in%20Powershell%20now%20that%20we've%20changed%20our%20policies%20regarding%20file%20retention.%20We%20want%20to%20get%20rid%20of%20the%20pre-existing%202020%20folder%20to%20minimise%20the%20folder%20structure%20complexity%20for%20users%20to%20navigate%2C%20and%20ensure%20they%20don't%20create%20a%20folder%20for%202021%20and%20copy%20files%20into%20there%3CA%20href%3D%22https%3A%2F%2Fprotigwelders.com%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%2C%3C%2FA%3E%20taking%20up%20Sharepoint%20space.%3C%2FP%3E%3CP%3EAs%20such%20I'm%20looking%20to%20extract%20the%20contents%20of%20the%202020%20folder%20in%20all%20of%20our%20Teams%20sites%20to%20the%20'Shared%20Documents%2FGeneral'%20location%2C%20then%20delete%20the%20empty%202020%20folder.%20So%20it%20goes%20from%3C%2FP%3E%3CP%3E'Shared%20Documents%2FGeneral%2F2020%2F%5Ball%20content%5D'%3C%2FP%3E%3CP%3Eto%3C%2FP%3E%3CP%3E'Shared%20Documents%2FGeneral%2F%5Ball%20content%5D'%3C%2FP%3E%3CP%3EThe%20MovePnP-Folder%20function%20naturally%20moves%20the%20entire%20folder%2C%20but%20it's%20the%20folder%20itself%20(not%20its%20contents)%20I'm%20looking%20to%20get%20rid%20of.%20The%20MovePnP-File%20function%20appears%20to%20work%20in%20strange%20ways%20and%20tells%20me%20I%20don't%20have%20rights%20to%20move%20files%20when%20I%20try%2C%20despite%20being%20a%20Global%20Admin.%20It%20also%20doesn't%20appear%20to%20work%20with%20wildcards%2C%20which%20I'd%20be%20expecting%20to%20use%20to%20ensure%20all%20the%20contents%20of%20a%20folder%20are%20selected.%3C%2FP%3E%3CP%3EI'm%20looking%20to%20have%20this%20recur%20for%20all%20the%20Teams%20sites%20in%20our%20environment.%3C%2FP%3E%3CP%3EMay%20I%20have%20some%20assistance%20here%2C%20please%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1977340%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

I'm attempting to remove some unnecessary parents folders from our Sharepoint Online sites in Powershell now that we've changed our policies regarding file retention. We want to get rid of the pre-existing 2020 folder to minimise the folder structure complexity for users to navigate, and ensure they don't create a folder for 2021 and copy files into there, taking up Sharepoint space.

As such I'm looking to extract the contents of the 2020 folder in all of our Teams sites to the 'Shared Documents/General' location, then delete the empty 2020 folder. So it goes from

'Shared Documents/General/2020/[all content]'

to

'Shared Documents/General/[all content]'

The MovePnP-Folder function naturally moves the entire folder, but it's the folder itself (not its contents) I'm looking to get rid of. The MovePnP-File function appears to work in strange ways and tells me I don't have rights to move files when I try, despite being a Global Admin. It also doesn't appear to work with wildcards, which I'd be expecting to use to ensure all the contents of a folder are selected.

I'm looking to have this recur for all the Teams sites in our environment.

May I have some assistance here, please?

0 Replies