Skip to content
The Bits That Byte
  • About
May 7, 2012 / PowerShell

Selectively Bulk Undeclare Records in SharePoint 2010 with PowerShell

While testing a Records Library in SharePoint 2010, the records will become locked and undeclaring records one by one (if you have the capability to undeclare records enabled through your Library and Site Records Declaration Settings) can be a tedious task. There may be others times when a content migration could go wrong, the Content Organizer might route to the wrong location, etc. in which you need to clear out the records in bulk without deleting the Records Library.

To be clear, I am old school when it comes to records. Once declared, I believe they should stay until the day of disposition… but even I need to test or clean up items that are clearly outside of the intent of the Records Management Program Office.

To that end, I have created the following script to allow a SharePoint Administrator the capability to selectively bulk undeclare records (in case you don’t want to undeclare everything). You will need to create a .CSV file named RecordsList.CSV with the following headings:

SiteURL
RecordLibraryName
RecordID

Here is the script, including notes. You will need to copy the script into NotePad and save it with the .ps1 extension and run it from your SharePoint 2010 Web Front End Server in the directory listed in the script notes.  Enjoy!

# Author: Kelly Rusk
# Website: thebitsthatbyte.com
# Created Date: May 7, 2012
# Description:
#
# This script selectively bulk undeclares records as listed in
# the RecordList.csv. The Record ID is the ID of the item in the library.
# You will need to pull the IDs from the library itself by creating a view.
# This intent of this script is for cleaning up test Records Libraries, or
# libraries where the records were mistakenly placed.
# The .CSV needs to be saved to “C:\PowerShell\” directory.
# If this directory does not exist, you will need to create it.
#
# Running this script requires running PowerShell with elevated privileges so right
# click the SharePoint 2010 Management Shell and select “Run as administrator” then use
# change directory commands and tabs to run the PS1 from its directory.

$SPAssignment = Start-SPAssignment
$undeclarelist = Import-Csv -path c:\PowerShell\RecordsList.csv
$undeclarelist | ForEach-Object {
$SPWeb = Get-SPWeb $($_.’SiteURL’) -AssignmentCollection $spAssignment
$SPList = $SPWeb.Lists[“$($_.’RecordLibraryName’)”]
$SPItem = $SPList.GetItemById(“$($_.’RecordID’)”) [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($SPItem)}
Stop-SPAssignment $SPAssignment

Post navigation

Previous Post:

Databases in the Cloud with SQL 2012 Express Edition and SQL Azure “Free” Trial

Next Post:

Getting Started with the SharePoint 2013 Preview

10 Commments

  1. Karen says:
    May 10, 2012 at 3:45 pm

    This is exactly what I was looking for but I am getting an error. Can you help? this is my script and error:
    $SPAssignment = Start-SPAssignment
    $undeclarelist = Import-Csv -path c:\PowerShell\RecordsList.csv
    $undeclarelist | ForEach-Object {
    $SPWeb = Get-SPWeb $($_.’SiteURL’) -AssignmentCollection $spAssignment
    $SPList = $SPWeb.Lists[“$($_.’RecordLibraryName’)”]
    $SPItem = $SPList.GetItemById(“$($_.’RecordID’)”) [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($SPItem)}
    Stop-SPAssignment $SPAssignment

    ERROR:
    Unexpected token ‘Microsoft.Office.RecordsManagement.RecordsRepository.Records’ in expression or statement.
    At C:\powershell\UndeclareList.ps1:6 char:113
    + $SPItem = $SPList.GetItemById(“$($_.’RecordID’)”) [Microsoft.Office.RecordsManagement.RecordsRepository.Records] <<<< ::UndeclareItemAsRecord($SPItem)}
    + CategoryInfo : PasrserError: (Microsoft.Offic…ository.Records:
    String) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

    DATA IN csv FILE:
    SiteURL RecordLibraryName RecordID
    http://server/crm Opportunities 2004
    http://server/crm Opportunities 2005
    http://server/crm Opportunities 5079
    http://server/crm Opportunities 5080
    http://server/crm Opportunities 5083
    http://server/crm Opportunities 5084

    Reply
    1. Kelly says:
      May 21, 2012 at 4:19 pm

      Hi Karen,

      What account are you running this with? Can you run the script with the Farm Account?

      Regards,

      Kelly

      Reply
  2. RichardM says:
    July 9, 2012 at 6:43 pm

    Are spaces allowed in the RecordLibraryName column? Eg: the library name is ‘Church Records’

    Richard

    Reply
    1. Kelly says:
      July 17, 2012 at 2:33 pm

      Yes, I believe so. I would give it a test as it should respect the spaces.

      Reply
  3. Ankit says:
    February 26, 2013 at 10:56 am

    Hi Kelly,
    I am also getting the same error which Karen is getting.
    I am running with Farm Acccount.

    please tell me if any solution for this.

    Reply
    1. Kelly says:
      March 6, 2013 at 9:50 pm

      Hi Ankit,

      Are you running PowerShell as an Administrator?

      Regards,

      Kelly

      Reply
  4. Manoj says:
    April 29, 2013 at 10:40 am

    I got the error:

    Unexpected token ‘Microsoft.Office.RecordsManagement.RecordsRepository.Records’
    in expression or statement.
    At D:\Patches\UnDeclare.ps1:6 char:113
    + $SPItem = $SPList.GetItemById(“$($_.’RecordID’)”) [Microsoft.Office.RecordsMa
    nagement.RecordsRepository.Records] <<<< ::UndeclareItemAsRecord($SPItem)}
    + CategoryInfo : ParserError: (Microsoft.Offic…ository.Records:
    String) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

    I solved it by putting a line break between the line that undeclares the record and the line "$SPItem = $SPList.GetItemById(“$($_.’RecordID"

    Reply
    1. Igor says:
      December 2, 2013 at 10:50 pm

      I had the same error and putting the line break as you suggested fixed it for me as well. Thanks!

      Reply
  5. Trey says:
    October 29, 2013 at 7:34 pm

    I am still getting the above error…tried as Farm account and another Admin account. No dice…any other ideas?

    Reply
    1. Trey says:
      October 29, 2013 at 7:43 pm

      At line:4 char:51
      + $SPItem = $SPList.GetItemById(“$($_.’RecordID’)”)
      [Microsoft.Office.RecordsManag …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ~~~
      Unexpected token ‘[Microsoft.Office.RecordsManagement.RecordsRepository.Records
      ]::UndeclareItemAsRecord’ in expression or statement.
      + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
      ception
      + FullyQualifiedErrorId : UnexpectedToken

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sitecore Technology MVP

Categories

  • AngularJS
  • Azure
  • CSS3
  • HTML5
  • Hyper-V
  • JavaScript
  • jQuery
  • OneDrive
  • PowerShell
  • Responsive Web Design
  • Search
  • SEO
  • SharePoint
  • Sitecore
  • SQL 2008 R2
  • SQL 2012
  • Tech Review
  • Tech Toy
  • Technical Resources
  • Uncategorized
  • Visual Studio
  • Web Content Management
  • Windows 8
  • Windows 8 App
  • Windows App
  • Windows Server 2008 R2
  • Workflow

Sponsored Links

Recent Posts

  • Autofail: A Big Azure Autoscale Limitation and What To Do
  • Got Fixes? A Sitecore Troubleshooters Guide to Sitecore Hotfixes
  • Sitecore 10 Application Roles, Storage Roles, and Indexes
  • Don’t Copy Sitecore Databases Across Environments, Sync Instead
  • Hey Sitecore PaaS! Where are My Modules?

Blogroll

  • Colins Sitecore Tech Blog
  • Sitecore Architecture – Grant's Sitecore Rants
January 2021
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031
« Dec    
© 2021 thebitsthatbyte.com - Powered by SimplyNews