Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $w = get-spweb http://acme.com/sites/mwi
- $list = $w.Lists["JournalEntry"]
- $destList = $w.Lists["JurnalEntryArchive"]
- $archDate = get-date "Jan 1 2015"
- function CheckIfArchive($list, $id, $archDate) {
- $ret = $false
- $itm = $list.GetItemById($id)
- $Submitted = -1
- $Archived = -1
- if($itm -ne $null){
- $SubmissionDate = $itm["SubmissionDate"]
- if($SubmissionDate -ne $null -and $archDate.CompareTo($SubmissionDate) -eq 1){
- $Archived = $itm["Archived"]
- if($Archived -ne $null -and $Archived -ne '' -and $Archived -eq 1){
- $ret = $true
- }
- $Submitted = $itm["Submitted"]
- if($Submitted -ne $null -and $Submitted -ne '' -and $Submitted -eq 1){
- $ret = $true
- }
- }
- }
- #Write-Host "$($id): $($SubmissionDate) $($Archived) $($Submitted): $($ret)"
- return $ret
- }
- function CopySpItem($sourceList, $destList, $id){
- $destItem = $destList.Items.Add();
- $sourceItem = $sourceList.GetItemById($id)
- $sourceItem.Fields |%{
- $f = $_;
- if($f.ReadOnlyField -eq $false -and $f.InternalName -ne "Attachments" -and $sourceItem[$f.InternalName] -ne $null){
- $destItem[$f.InternalName] = $sourceItem[$f.InternalName];
- }
- }
- $destItem.Update();
- }
- $allIds = $list.Items|%{$_.ID}
- foreach($id in $allIds) {
- $doDelete = CheckIfArchive $list $id $archDate
- if($doDelete) {
- Write-Host -NoNewLine "x"
- CopySpItem $list $destList $id
- }
- else { Write-Host -NoNewLine "." }
- }
- foreach($id in $allIds) {
- $doDelete = CheckIfArchive $list $id $archDate
- if($doDelete) {
- Write-Host -NoNewLine "x"
- $itm = $list.GetItemById($id)
- $itm.Delete()
- }
- else { Write-Host -NoNewLine "." }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement