How to recover List Items from Recycle bin using Powershell by having item Guid
-
07-10-2020 - |
Question
With following code I have recycled list items and have stored item GUID
in $DeletedItem
:
for($i=$ListItems.Count-1; $i -ge 0; $i--)
{
write-host "Deleted List Item with ID:$($ListItems[$i].ID)"
$DeletedItem= $ListItems[$i].recycle()
}
I want to recover the items by using saved item's GUIDs
, Is that possible? How I recover list items using powershell?
Solution
Here you go:
Assuming $DeletedItem = $ListItem.recycle()
:
$site = Get-SPSite http://server/sites/site
$site.RecycleBin.Restore($DeletedItem)
Put it into a foreach cycle and you'll be able to restore a collection of items:
Assuming $DeletedItems
is a collection of GUIDs:
ForEach ($deletedGuid in $DeletedItems)
{
$site.RecycleBin.Restore($deletedGuid)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange