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
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
Hi Karen,
What account are you running this with? Can you run the script with the Farm Account?
Regards,
Kelly
Are spaces allowed in the RecordLibraryName column? Eg: the library name is ‘Church Records’
Richard
Yes, I believe so. I would give it a test as it should respect the spaces.
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.
Hi Ankit,
Are you running PowerShell as an Administrator?
Regards,
Kelly
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"
I had the same error and putting the line break as you suggested fixed it for me as well. Thanks!
I am still getting the above error…tried as Farm account and another Admin account. No dice…any other ideas?
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