1

I have a large list that I need to archive list items off to a different list within the same site. (I'll make the list into a template to make the archive lists.) The list is an InfoPath list that has attachments and has version history enabled. Can PowerShell move the list items from the main list to the other and keep the attachments and version history? I'm also still quite new to PowerShell so I wanted to get some insight from others who have more experience with this sort of thing.

Also I'm using SharePoint 2013 On Prem.

  1. I simply want to know if this is even possible.

  2. I've started my script and was able to get my list and filter the content I want to move, I just am unsure how to tackle moving the items and keeping the version history and attachments for the list items that are moved.

Here is what I have so far:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Function global:Get-SPWeb($url)

{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();        
             }
    return $web
}

#Get the web and List

$Web = Get-SPWeb "https://ExampleSite.com/SiteOne"

$SourceList = $web.Lists["List 1"]

$TargetList = $Web.Lists["List 2"]


#Get all items Created before target date   
$Query = New-Object Microsoft.SharePoint.SPQuery
$Query.Query = "@
<Where>
    <Eq>
        <FieldRef Name='Status' />
        <Value Type='Choice'>Complete</Value>
    </Eq>
</Where>"

#Get List Items matching the query

$ListItems = $SourceList.GetItems($Query)

Write-host "Total Number of Items: "$ListItems.count

1 Answer 1

0

Within the same site scope a list or library (the list GUID ID remains the same) can't be imported using PS import-spweb after exporting the same using PS Export-SPweb

I would do the followings:

  1. Create a sub site for archival purpose
  2. Export the list/library
  3. Import the list/library
  4. Delete the files from the source library (I guess, completed)
  5. Delete the files from the destination/archived library (not completed)
  6. Moving forward, use Workflow to archive files

Here is an example

$libraryName="MyLibrary"
$PathExpFile="E:\Temp\$libraryName.cmp"

#Source and Destination
$SourceWebURL="http://ABC.com/sites/source"
$TargetWebURL="http://ABC.com/sites/source/Archive"

Export-SPweb $SourceWebURL -ItemUrl $SourceList.DefaultViewUrl -IncludeUserSecurity -IncludeVersions All -path $PathExpFile -nologfile

import-spweb $TargetWebURL -IncludeUserSecurity -path $PathExpFile -nologfile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.