Unable To Cast Object Of Type ‘Microsoft.SharePoint.PowerShell.SPCmdletSnapIn’

I was called in to a client to repair this error following a migration to SharePoint 2013. I talked to a few colleagues, and some actually have experienced with new SharePoint environments as well as migrated SharePoint environments. The approach that you use to build the environment also does not appear to be a relevant factor.

Most of the advice I got was to rebuild the environment. This certainly would work but also fixing the damn thing is an option as well.

The full error that you will receive is:

Add-PsSnapin : Cannot load Windows PowerShell Snap-In
Microsoft.SharePoint.PowerShell because of the following error: Unable to cast object of type ‘Microsoft.SharePoint.PowerShell.SPCmdletSnapIn’ to type
At C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\CONFIG\POWERSHELL\Registration\SharePoint.ps1:3 char:1
+ Add-PsSnapin Microsoft.SharePoint.PowerShell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.SharePoint.PowerShell:St
   ring) [Add-PSSnapin], PSSnapInException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad

The CustomPSSnapIn Serves as a base class for snap-ins that are used to register a list of cmdlets and providers, this is standard PS shit nothing to fancy. The SPCmdletSnapIn is the destination cast type, this is the equivalent of the former, however specific with the relevant SharePoint additions.

Nothing to fancy going on here, and type cast exceptions outside of object reference errors are probably the most common error people run into. However fixing something like this when they are baked in types is a pain in the ass because you really don’t have access to the types, they are shipped with the product. The types themselves are the issue, and you don’t know whether its the SharePoint or Windows Management Framework types!

For me, it was the Windows Management Framework types that were causing this issue. To repair this error, simply do a an uninstall on Microsoft Windows Management Framework 3.0 (KB2506143) and reinstall using this http://www.microsoft.com/en-us/download/details.aspx?id=34595.