SharePoint Online: Copy picture library

H Risbud 251 Reputation points
2022-01-07T23:06:49.563+00:00

This is SharePoint Online question:

I would like to make duplicate (copy of) picture library based on existing picture library. Existing picture library has only 339 items. When I try to browse or copy items to new picture library I'm getting this error message "The result set is too large".
I've indexed columns of existing picture library but still not helping. Please shade light on how do I make a copy of existing Picture library?

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. JoyZ 18,111 Reputation points
    2022-01-10T06:53:25.067+00:00

    @H Risbud ,

    Use below PnP PowerShell to copy all files and folders between Document Libraries with Metadata to check if it works:

    #Function to copy all Items from one library to another  
    Function Copy-AllDocuments($SourceLibraryName, $TargetLibraryName)  
    {  
        #Get Source and Target Libraries  
        $SourceLibrary = Get-PnPList -Identity $SourceLibraryName -Includes RootFolder  
        $TargetLibrary = Get-PnPList -Identity $TargetLibraryName -Includes RootFolder  
        #Copy All Files and Folders from Source to Target Library  
        Copy-PnPFile -SourceUrl $SourceLibrary.RootFolder.ServerRelativeUrl -TargetUrl $TargetLibrary.RootFolder.ServerRelativeUrl -OverwriteIfAlreadyExists -Force -SkipSourceFolderName  
        #Get All Items from Source Library  
        $SourceItems = Get-PnPListItem -List $SourceLibraryName  
        $TargetItems = Get-PnPListItem -List $TargetLibraryName  
        #Get All Items in the Source Library  
        ForEach($SourceItem in $SourceItems)  
        {  
            #Get Metadata from Source Items  
            $Metadata = @{  
                'Title' = $SourceItem.FieldValues.Title  
                'Created'= $SourceItem.FieldValues.Created.DateTime  
                'Modified' = $SourceItem.FieldValues.Modified.DateTime  
                'Author' = $SourceItem.FieldValues.Author.Email  
                'Editor' = $SourceItem.FieldValues.Editor.Email  
                }  
            #Update Metadata in Target Items  
            ForEach($TargetItem in $TargetItems)  
            {  
                If($SourceItem.FieldValues.FileLeafRef -eq $TargetItem.FieldValues.FileLeafRef)  
                {  
                    Set-PnPListItem -List $TargetLibrary -Identity $TargetItem.Id -Values $Metadata | Out-Null  
                }  
            }  
        }  
    }  
    #Connect to PnP Online  
    $SiteURL = "https://crescent.sharepoint.com/sites/marketing/"  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
    #Call the function to copy all files between document libraries  
    Copy-AllDocuments "Project Documents" "Temp"  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  2. H Risbud 251 Reputation points
    2022-01-20T15:54:14.203+00:00

    I've taken following approach item by item as Copy-PnPFile and Get-PnPListItem was giving error "The result set is too large" even using -PageSize 1000enter code here**

    #Function to copy all Items from one library to another
    Function Copy-AllDocuments($SourceLibraryName, $TargetLibraryName)
    {
        $SourceItemsMetadata = @()
        #Get Source and Target Libraries
        $SourceLibrary = Get-PnPList -Identity $SourceLibraryName -Includes RootFolder
        $TargetLibrary = Get-PnPList -Identity $TargetLibraryName -Includes RootFolder
        #Copy All Files and Folders from Source to Target Library
        #You must need to know range of source item's ids
        for($i=1; $i -le 3000;$i++)
        {
            $Query = "<View><Query><Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + $i + "</Value></Eq></Where></Query></View>"
            $SourceItem = Get-PnPListItem -List $SourceLibrary.Id -Query $Query -ErrorAction SilentlyContinue        
            Copy-PnPFile -SourceUrl "$($SourceItem.FieldValues.FileRef)" -TargetUrl "$($TargetLibrary.RootFolder.ServerRelativeUrl)" -OverwriteIfAlreadyExists -Force
            $Metadata = @{
                #Get all required metadata of item
                'Title' = $SourceItem.FieldValues.Title
                'Created'= $SourceItem.FieldValues.Created.DateTime
                'Modified' = $SourceItem.FieldValues.Modified.DateTime
                'Author' = $SourceItem.FieldValues.Author.Email
                'Editor' = $SourceItem.FieldValues.Editor.Email
                'FileLeafRef' = $SourceItem.FieldValues.FileLeafRef
                }
            $SourceItemsMetadata += $Metadata;        
        }
        $TargetItems = Get-PnPListItem -List $TargetLibraryName
        #Update Metadata in Target Items
        ForEach($TargetItem in $TargetItems)
        {
            ForEach($SourceItemMetadata in $SourceItemsMetadata){
                If($SourceItemMetadata.FileLeafRef -eq $TargetItem.FieldValues.FileLeafRef)
                {
                    Set-PnPListItem -List $TargetLibrary -Identity $TargetItem.Id -Values $SourceItemMetadata | Out-Null
                }
            }
        }
    }
    #Connect to PnP Online
    $SiteURL = "https://crescent.sharepoint.com/sites/marketing/"
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
    #Call the function to copy all files between document libraries
    Copy-AllDocuments "Project Documents" "Temp"
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.