SharePoint PowerShell Restore Recycle Bin

I would not identify myself as a programmer or developer but I certainly enjoy technology and writing scripts to solve problems that I encounter. I am pretty comfortable in my Microsoft Excel formulas and my ability to diagnose problems. I understand the logic that needs to happen but not the syntax to make it happen.

Earlier today I had an employee accidentally delete some 40,000 objects from my SharePoint Document Library that is shared company-wide. The browser tools with SharePoint Online (2016) only gave me the ability to restore a few files or folders at a time. I decided to try to solve my problem with PowerShell. I was not that familiar with the PnP PowerShell tools but they helped me solve my problem:

First, I launched PowerShell in administrator mode and installed the PowerShell Gallery:

Install-Module SharePointPnPPowerShellOnline

Second, I got connected to my SharePoint Online:

Connect-PnPOnline -Url https://contoso.sharepoint.com

Third, I wrote a script to see if I could see a count of the files in the recycle bin:

#Count of the Items in the First Stage Recycle Bin
(Get-PnPRecycleBinItem -FirstStage).count

I noticed that it included folders and only wanted to restore the files. SharePoint will restore the folder structure automatically. So I cleaned up my scrip to only include files:

#Show Count of “File” in the First Stage Recycle Bin
(Get-PnPRecycleBinItem -firststage | ? ItemType -like "File").count

Finally, I was able to use my script that would restore the 40,000 files:

#Restore All “File” in the First Stage Recycle Bin
Get-PnPRecycleBinItem -firststage | ? ItemType -like "File" | Restore-PnpRecycleBinItem -Force

There were a few phone calls to consultants that were not of much help. I am posting this online in hopes that it might be helpful to others. Enjoy!

Farook Portrait

February 5, 2015 5:08pm

Farook Portrait. It has been some time since I have updated my website/blog. I figured I would share a portrait that was taken back May of 2014. My dear friend Adam had given me a good trim and spring was in full motion. My beard is substantially bigger now but that can easily change with a quick stop to the barber shop.

Most of my current pictures and updates are now found on Facebook or Instagram but this website is still here for me to share some of my other wonderings and photography. Hope you enjoy the new layout and design.

Cheers!

Farook Khan

Montana

Wednesday, 26 June 2013, 8:38pm

Montana! I was able to break away for a little bit and snap some pictures while working up in Power, Montana. These photographs were taken along the I-15 freeway that connects Helena and Great Falls. We happened to be passing through right during sunset on a cloudy afternoon providing for some spectacular images of the beautiful countryside and the Missouri River. Enjoy!

Montana-2013-06-25-1

Montana-2013-06-25-2

Montana-2013-06-25-3

Montana-2013-06-25-4

Montana-2013-06-25-5

Rockport Camping Trip

Sunday, 23 June 2013, 5:42pm

Rockport Camping Trip! It was a perfect weekend for a getaway to the mountains. We packed our camping gear and drove to Rockport State Park just a few miles past Park City. The weather was perfect and I managed to capture a few pictures from the trip.

Rockport-2013-06-22-23

Rockport-2013-06-22-16

Rockport-2013-06-22-19

Rockport-2013-06-22-13

Rockport-2013-06-22-25

Spring Moab Trip 2013

Tuesday, May 21 2013, 7:51pm

Spring Moab Trip 2013! Last weekend I had the opportunity to sneak away to Southern Utah and enjoy the red rocks and national parks that surround Moab, Utah. I was able to catch up with my good friends Hilton and Fred who were visiting from California. They had spent the whole week backpacking and I was able to join them for the last part of their trip. I then spent the rest of the weekend with Mike exploring Arches National Park. It wouldn’t be a weekend away without taking a few pictures. Enjoy!

Moab 1

Moab 2

Moab 3

Moab 4

Moab 5

Moab 6

Moab 7

Moab 8

Moab 9

Moab 10

Moab 11

Moab 12

Portrait Photography

Wednesday, 13 March 2013, 6:45pm

Portrait Photography! Over the last few weeks I have been taking various portraits at work for our new marketing initiatives. It is always fun to develop my personal hobbies while at work. It makes going to work everyday such a pleasure.

Today was one of the rare occasions where I ended up on the other side of the camera and got a pretty good portrait.

20130313-203240.jpg

Multimedia Engineer

Saturday, 2 March 2013, 3:41pm

Multimedia Engineer! Work is keeping me busy today with a fun new project involving the production of safety training videos and other various marketing materials. It is fun that my personal hobbies often translate into projects for work.

20130302-154418.jpg

Red Butte Gardens

Sunday, 6 May 2012, 10:03am

Red Butte Gardens! After several months of time consuming school and work I managed to take my camera out of the closet. It was great to go up to Red Butte Gardens and photograph some of the beautiful flowers. It was a beautiful Saturday afternoon in Salt Lake.

Big Piney Wyoming

Monday, 5 September 2011, 10:50pm

Big Piney Wyoming! Work sent me all over the mountain west this summer with trips to Nevada, Idaho, Utah and Wyoming. I had many opportunities to capture this beautiful landscape with my trusty little Canon S95.

One of the jobs sites I worked at was located near Big Piney, Wyoming. I was impressed with the vast landscape, beautiful scenery and the open sky with picturesque cloud formations.

This picture was taken just south of Big Piney driving toward Kemmerer on my way back to Salt Lake City, Utah. It was edited using Aperture 3 and captured on 5 August 2011 around 6pm.