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.
I simply want to know if this is even possible.
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