Our company is doing a migration from SharePoint sub-sites to new sites.
The only things being moved are document libraries, since we'll be moving a lot of libraries I have looked into doing this with PowerShell.
I have been using PnP PowerShell with Move-PnPFile
. But I'm struggling to move an entire library worth of content. I can only get PowerShell to work for individual folders/files within the library.
I have tried to list items and loop through them to move, but I cannot seem to get this working either.
I'd like to move the library from https://companyname.sharepoint.com/IT/Test
to https://companyname.sharepoint.com/sites/IT/Test
Connect-PnPOnline -Url 'https://companyname.sharepoint.com/IT' -UseWebLogin
$sourceUrl = 'https://companyname.sharepoint.com/IT/Test/'
$targetUrl = 'https://companyname.sharepoint.com/sites/IT/Test/'
$allDocs = (Get-PnPListItem -List 'Test').FieldValues
foreach ($item in $allDocs)
{
Move-PnPFile -SourceUrl ($sourceUrl + $item.FileLeafRef) -TargetUrl ($targetUrl + $item.FileLeafRef) -Force
}
Basically this is what I am trying to achieve. I have tried all sorts of different variations of ways to get items name/path, used relative URLs, different URLs, none has worked for me. (Get-PnPListItem
also lists all items, I only need top level files/folders as all sub-files will move with the folder)
I have full admin access permission to both sites, and I am a global administrator.