Quantcast
Channel: SharePoint 2010 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 17574

Undeclare SharePoint in-place records using PowerShell

$
0
0

Hello all,

I have been trying to find the best solution to undeclare all the records in one of my document libraries.  I have tried tried several scripts but they all seem to have various issues. I finally got the one below to debug without issues. However when I run the script I get no response. I setup PowerShell to log and it has nothing in it too. Any help would be greatly appreciated!!

function UndeclareRecords($siteUrl, $libraryName) {
  function IsRecord($item) {
    [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsRecord($item)
  }

  function EnsureCheckedIn($item) {
    if ($item.File.CheckOutType -ne [Microsoft.SharePoint.SPFile+SPCheckOutType]::None `
        -and (-not [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsLocked)) {
      write-host "Checking in file: $($item.Url)"
      $file.CheckIn("Checked in by script prior to undeclaring as record", ($
                    [Microsoft.SharePoint.SPCheckinType]::MinorCheckIn)
    }
  }

  function UndeclareRecord($item) {
    write-host "Undeclaring record: $($item.Url)"
    [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($item) 
  }

  $site = Get-SPWeb $siteUrl
  $list = $site.Lists[$libraryName]
  $list.Items | foreach { 
    if (IsRecord $_) {
      EnsureCheckedIn $_
      UndeclareRecord $_
    }
  }

  $site.Dispose()
}



Viewing all articles
Browse latest Browse all 17574

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>