• Skip to primary navigation
  • Skip to main content
site logo
  • About
    • Approach
    • Partnerships
    • Mission
    • Leadership
    • Awards
    • Arraya Cares
  • Solutions
    • Solutions

    • Hybrid Infrastructure
      • Hyperconverged
      • Infrastructure as a Service
      • Servers, Storage, and Virtualization
      • Data Protection
      • Disaster Recovery & Business Continuity
    • Apps & Data
      • AI
      • Automation
      • Customizations
      • Visualizations & Integrations
      • Migrations
    • Network
      • Enterprise Networks
      • Wireless Connectivity
      • Cloud Networking Solutions
      • IoT
    • Cybersecurity
      • Endpoint Security
      • Network Security
      • Cloud Security
      • Application Security
    • Modern Workplace
      • Microsoft Licensing
      • Productivity & Collaboration
      • Modern Endpoint Deployment & Management
      • Microsoft Compliance & Risk
      • Backup
      • Cloud
  • Services
    • Services

    • Managed Services
      • Service Desk
      • Outsourced IT
      • Managed Security
      • Managed NOC
      • Arraya Adaptive Management for Microsoft Technologies
      • ADEPT: Arraya's White Label Program
    • Advisory Services
      • Assessments
      • Strategy
      • vCTO
      • vCISO
      • Enterprise Architecture
    • Staffing
      • Infrastructure Engineering
      • Security & Compliance
      • Application & Software
    • Professional Services
      • Project Management 
      • Systems Integration 
      • Mergers & Acquisitions
      • Knowledge & Skills Transfer 
  • Industries
    • Education
    • Finance
    • Healthcare
    • Legal
    • Manufacturing
    • Software and Services
  • Insights
    • News
    • Blog
    • Events
    • Videos
    • Case studies
  • Careers
  • CSP Login
search icon
Contact Us

SharePoint Tip: Use this Script to Archive Your Way to Greater Performance

A common problem with SharePoint, regardless of version, is that once a list or library has more than 2000 items in it, performance is impacted. Once you reach 5000 items, the impact becomes severe. The issue lies with a fundamental part of the interaction between SQL and SharePoint and, because of that, it is not easily solved.

While the usual solution is to leverage views to minimize the impact on any one user, we’re going to look at using a PowerShell script to clean up older items and move them to an archive. Our scenario is this: You have a list you made last year for sales contacts; but you’re well over 2000 items now and want to move the 2018 entries to an “archive” list. Ideally, you want a process you can easily leverage and you don’t want to use the document management feature for a variety of reasons that we’ll leave out for now.

If you’re looking at the above scenario, you’re looking for a PowerShell script solution for a reason and we have it. This script could be leveraged once a year, every year, to clear out the prior year’s list contents to an “Archive.” This archive list presumably won’t grow as each successive year would be its own list. The data remains in SharePoint and is easily leveraged, but you’re not crowding and slowing the most current entries.

The first part of this process is to create the archive list in SharePoint. This is simple enough, we’re just going to save an empty template of our current list to get all of the settings and columns just right.

 

SharePoint Archive script SharePoint archive script sharepoint archive script

Now that we have our destination list, we just need the script. With a few minor changes, we could alter this script to be selective for any date or other criteria captured by our fields. The first part is our establishment of the values for our operations:

 

# Created by Matt Vignau, Arraya Solutions, Inc. 4-16-2019

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

 

#Configuration variables

$WebURL = “<Insert Site URL here>”

$SourceListName = “<Name of list that needs archiving>”

$TargetListName= “<Name of list to archive content to>”

 

We need only add the URL of the website that contains our lists and the name of the source list, the one we wish to trim from, and the target list, where we want our items to appear.  When we say the “name”, we mean the actual display name of the list that you have chosen for them.

The next part of the code sets up the objects we need to carry out the operation and are fairly straightforward:

 

#Get Objects

$web = Get-SPWeb $WebURL

$SourceList = $web.Lists[$SourceListName]

$TargetList = $web.Lists[$TargetListName]

$CutOffDate = [datetime](“1/1/19”)

 

#Get all source items

$SourceColumns = $sourceList.Fields

$SourceItems = $SourceList.GetItems();

 

Note that you could set the date to be anything you wish to change the created date you want to trim from.  After this, we need only set up a loop to go through and make item copies, one column at a time.

 

#Iterate through each item and add to target list

Foreach($SourceItem in $SourceItems)

{

$CreatedDate = [datetime]($SourceItem[“Created”])

if( $CreatedDate -le $CutOffDate)

{

Write-Host $SourceItem[“ID”]

$TargetItem = $TargetList.AddItem()

Foreach($column in $SourceColumns)

{

if($column.ReadOnlyField -eq $False -and $column.InternalName -ne “Attachments”)

{

$TargetItem[$($column.InternalName)] = $sourceItem[$($column.InternalName)]

}

}

$itemsToDelete += $SourceItem

$TargetItem.Update()

}

}

 

Finally, we need to clean up the old items with the following loop:

 

#Movement is complete, move on to delete

Write-Host “Item movement completed, proceeding to delete old items…”

 

Foreach ($itemToDelete in $itemsToDelete)

{

Write-Host “Now deleting item #” + $itemsToDelete[“ID”]

$itemToDelete.Delete()

}

 

Write-Host “Items have been deleted”

 

That’s all there is to it!

Next Steps: Learn more SharePoint tips and tricks

Interested in learning more about how to optimize your SharePoint environment? Reach out to us at https://www.arrayasolutions.com//contact-us/. Also, let us know what you think of this blog by way of social media. Arraya can be found on LinkedIn, Twitter, and Facebook. While you’re there, follow us to stay up to date with our industry insights and unique IT learning opportunities.

Arraya Insights
Back to Top
Arraya Solutions logo

We combine technological expertise and personal service to educate and empower our customers to solve their individual IT challenges.

518 Township Line Road
Suite 250, Blue Bell, PA 19422

p: (866) 229-6234     f: (610) 684-8655
e: info@arrayasolutions.com

  • Careers
  • Privacy Policy
  • Contact Us

© 2025 Arraya Solutions. All rights reserved.

Facebook Twitter YouTube LinkedIn
Manage Cookie Consent
We use cookies to enhance your experience. By selecting “Accept,” you agree to our cookie policy.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}