Home SharePoint maintenance - the power of powershell
Post
Cancel

SharePoint maintenance - the power of powershell

A migration of content from an old version of SharePoint can be a tedious task - let some great little PowerShell commands help out! Syndication

Sometimes weekend plans aren’t quite what you expect. I thought I would be settling into some 80s tunes on my walkman while working on my IndieWeb hobby projects.

Instead, I spent much of my weekend migrating over 7 GBs of content from a legacy SharePoint 2010 site to SharePoint 365. It wasn’t pretty.

Back to the Future

First, I had to open Edge in IE mode (it still exists - it won’t die!) to allow me to utilize the “Open in File Explorer” option - it is disabled otherwise. From there, I was able to export large swaths of data without much manual interference. The transfer choked on a few larger files, but I was able to take note of them and copy over individually after the export completed.

SharePoint 2010 using Edge's IE Mode to display the necessary options

Most of our SharePoint content was just Document Libraries, so the data came over fairly easily. Some power users (IT of course and the Project teams) has utilized Wikis, and that was a pain point. You’d think that the files would be simple HTML or Markdown that I could just copy over, right? Wrong. It’s just an ASPX page with controls that call into a database to pull over the actual wiki content.

So that content couldn’t be automated. We will have to review each wiki page and decide if it still needs to be moved over, and do so manually.

In the meantime, I started looking at the downloaded content. There were a lot of empty folders - “m”, “SiteAssets”, “Forms”. Or they had some .aspx files which weren’t going to do me any good.

Taking the ShortCut

I found a couple of PowerShell commands that made this cleanup terrifingly easy. I’m listing those commands here, but take caution if you utilize them - you will need to change the file locations!

Before I run a script that could have damaging effects, I zipped up all the content for a backup in case things didn’t go well (but they did, be an optimist Jeff!)

First, I wanted to remove any .aspx page found - I tried copying these pages over but it didn’t work. That would have been easy, right? Remember, this command DELETES files for you! They aren’t coming back either - you won’t find them in your trash afterwards. I warned you!

1
Remove-Item 'C:\[YOUR_FOLDER_NAME]\*' -Recurse -Force -Include *.aspx

Then I decided to also remove .dotx template files. Your mileage may vary, but these weren’t of much use in our data.

1
Remove-Item 'C:\[YOUR_FOLDER_NAME]\*' -Recurse -Force -Include *.aspx

Finally, I recursively go through the rest of the folders, and delete any folder with no content. This gets a big tricky because you have to recursively walk down the folders.

The first command just shows you what will happen. The second one will do it!

1
(gci "C:\[YOUR_FOLDER_NAME]" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName | Out-GridView

Once you feel comfortable with the results, run it for real:

1
(gci "C:\[YOUR_FOLDER_NAME]" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | remove-item

And after only a few seconds…wallah…nice clean folder sets without a bunch of empty folders or code files that aren’t of any use for an import.

Wrapping it up

After this, I just created a new SharePoint 365 site, set permissions to view to only me and my team, and then started copying over the files.

Just as before, a few were too large to copy over through the normal “Upload Folder” option, so I found if I could upload them manually, one by one, it accepted them.

My plan is to make this site read only, and setup new site designs for each department. The content can then be copied over as needed.

While we wait - let’s update!

While the files were transferring, I took some time to setup a new version of PowerShell on my Mac and PC.

Then I installed Microsoft PowerToys on my pc laptop - a little kit I haven’t even thought about since the early 00’s! Some helpful items in there - a Preview pane, similar to my Mac for PDF, SVG, and Markdown files. A Hosts file editor (are you kidding I can type c:\windows\system32\drivers\etc in my sleep now) and most interesting, Video Conference Mute- just a little utility that stays ON TOP of the windows and offers some shortcuts that will work on any meeting app - Zoom, Teams, etc.

Finally, I decided to give my command line some bling with “Oh My Posh”. Not sure how I feel about it yet, but I have some similar functionality on my Mac with Termius.

Not the weekend I had in mind, but a productive one!

This post is licensed under CC BY 4.0 by the author.