Skip to content

Instantly share code, notes, and snippets.

@fabianneve
Last active October 31, 2018 15:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabianneve/f4e5b14644f0b0a9ac6dc36c0dffce2d to your computer and use it in GitHub Desktop.
Save fabianneve/f4e5b14644f0b0a9ac6dc36c0dffce2d to your computer and use it in GitHub Desktop.
# recycle bin's are tied to a site collection so we need a site collection object
$site = get-spsite https://webapplication/sitecollection
#we can see everything in the recycle bin like this:
$site.Recyclebin
#unfortunately, the above command dumps quite a lot to the screen.
#fortunately, we can pipe the output to other commands for filtering and cleanup.
#This command will return all the webs in the recyclebin
$site.Recyclebin | where {$_.itemtype -eq "web"}
#we can build on this by adding a sort statement,
#here I sort by dirname, which is the URL path the item would have been at before it was deleted
$site.Recyclebin | where {$_.itemtype -eq "web"} | sort dirname
# we can format the output into a nice list
$site.Recyclebin | where {$_.itemtype -eq "web"} | sort dirname | select title, itemtype, dirname, itemstate
#note that in the above listing, itemstate shows which recycle bin it's in (FirstStageRecyclebin = End user Recycle Bin Items, SecondStageRecycleBin = Deleted from end user Recycle Bin)
#here's one more application of filtering to show everything that's not a page nor a list item
$site.RecycleBin | where { $_.itemtype -ne "file" -and $_.itemtype -ne "ListItem" } | sort dirname | select title, itemtype, dirname
$site.RecycleBin | where { $_.itemtype -ne "ListItem" -and $_.dirname -like "team/jst/crm*" -and $_.itemtype -ne "FileVersion" } | sort dirname | select title, itemtype, DeletedDate, dirname | Out-GridView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment