When SharePoint GUI Fails, Let PowerShell Be Your Guide

During my time of providing SharePoint support, I’ve experienced a number of issues that required PowerShell to resolve. These were situations that for one reason or another, the user was unable to resolve the issue through the Graphic User Interface (GUI). That is, without performing some form of restore from a backup, PowerShell was the only answer to actually fix the problem.

Scenario 1: A solution that requires SharePoint Server is activated on a SharePoint Foundation site.

In this case, the solution broke the client’s site since it required functionality that doesn’t exist in SharePoint Foundation. After the solution was activated, they received a very descriptive “An unexpected error has occurred” message when accessing the site.

This scenario had a relatively simple solution (no pun intended). First, it was necessary to identify the offending solution. The following can be used to list all of the solutions in a site collection:

Get-SPUserSolution -site http://sitecollection

After I had the name for the solution, I was able to deactivate it with the following:

uninstall-SPUserSolution -Identity solution.name.wsp -site http://sitecollection

Scenario 2: An item in a SharePoint list becomes corrupted.

In this case, the list item did not have all of the fields that other items in the list had. It also had the unpleasant effect of locking up the browser window any time the item would be displayed on a page.

I attempted a number of things through the GUI including creating different views in an attempt to find a way to access the list item and delete it. All of the methods through the GUI were unsuccessful. Since interacting with the list through the GUI became virtually impossible, it was necessary to turn to PowerShell to exterminate the offending item.

Here is the script I used to delete the corrupted item:

$w = get-SPWeb -Identity http://server_name

$l = $w.GetList("/Lists/somelist/")

$listItem = $l.GetItemById(int) #replace “int” with the ID of the desired item

$listItem.Delete()

$w.Dispose()

Here is the lowdown on the script above:

  1. Lines 1-2 drill down into the SPWeb object to assign the list to the $l variable
  2. Line 3 assigns the corrupted list item to the $listItem variable
    a.  In this scenario, I was able to identify the corrupted list item by its ID, so I was able to get the corrupted list item with the getItemByID method.
  3. Line 4 deletes the selected item
  4. With Line 5, I didn’t want to forget to dispose the SPWeb object now that I’m finished with it!

The client’s list was usable again after getting rid of the corrupted list item.

Scenario 3: A site admin deletes the root site of a site collection.

For example, on the root site of a site collection, the admin does this:

Test Site Settings

I’ve run into this situation a number of times. Whenever you delete a sub-site of a site collection, it’ll go to the site collection recycle bin. But what happens when deleting the root site of a site collection? It effectively deletes the entire site collection.

Site Collection List

“My site collection was here a minute ago…”

Site Collection List Missing

“But now it is gone!”

There is not a way to recover this through the GUI, but thankfully, starting in SharePoint 2010 Service Pack 1, there is an easy method using PowerShell to recover a site collection that was deleted this way. Here is how to do it:

First, it is necessary to get a list of the deleted site collections in the farm.

Get-SPDeletedSite

SharePoint Deleted Site

Next, I’ll use the GUID of the SiteId to run the restore command for the desired site collection:

Restore-SPDeletedSite -Identity 866e583e-2c00-4518-a8c2-4132b87c431f

Now the test site collection has been restored:

Restore Site Collection List

So in recap, whenever you’ve run into an issue with SharePoint that you can’t resolve through the GUI, don’t be afraid to investigate a solution through PowerShell. It can often provide a simple answer!

VN:F [1.9.22_1171]
Rating: 10.0/10 (2 votes cast)

About Fpweb.net Crew

Our business is centered on bringing enterprise-class strategy, support, and security to your hosted or managed platforms no matter where you choose to deploy your environment. We specialize in providing managed services, cyber security, and expert, USA-based, 24/7 Absolute Support® on-premises, or in any cloud.
This entry was posted in PowerShell and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Let's make sure you're human first: *