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

Copper 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