Unanswered SharePoint 2010 Management Shell: Add-PSSnapin already added error

  • Wednesday, August 22, 2012 6:32 PM
     
      Has Code

    I have a number of servers across several farms, and I've never experienced this annoyance (low priority in the grand scheme of things) - when I open the SharePoint 2010 Management Shell, I get the error (or warning):

    Add-PSSnapin : Cannot add Windows PowerShell snap-in Microsoft.SharePoint.Power
    
    Shell because it is already added. Verify the name of the snap-in and try again
    .
    At C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONF
    IG\POWERSHELL\Registration\SharePoint.ps1:3 char:13
    + Add-PsSnapin <<<<  Microsoft.SharePoint.PowerShell
        + CategoryInfo          : InvalidArgument: (Microsoft.SharePoint.PowerShel
       l:String) [Add-PSSnapin], PSArgumentException
        + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad
       dPSSnapinCommand

    SharePoint.ps1 is an out-of-the-box file and is not the issue.  The issue is, it's trying to load a snap-in that has already been loaded.  But how is the snap-in already loaded?  I don't see any profile file under C:\Users\_username_\Documents\WindowsPowerShell either (where I used to load the snap-in in MOSS).

    Any ideas what's going on?

All Replies

  • Wednesday, August 22, 2012 6:37 PM
     
      Has Code

    Can you try to check whether the snap-in is loaded prior to loading it again?

    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }

  • Wednesday, August 22, 2012 6:47 PM
     
      Has Code

    Hi,

    Try this:

    Add-PSSnapin -Name <snapin> -ErrorAction SilentlyContinue

    I hope this will help you out


    Thanks, Rahul Rashu

  • Wednesday, August 22, 2012 6:56 PM
     
     
    I could do those things, but I'm talking about a file that ships with SP2010 and doesn't throw this error on any other server in my environment.  I shouldn't have to modify this file.
  • Wednesday, August 22, 2012 7:42 PM
     
      Has Code

    It sounds like the snap in might be loaded as part of your profile. The $PROFILE variable contains the path to your profile, running:

    notepad $PROFILE

    should load the profile up in Notepad. If the snapin is here, you can remove it.


    Jason Warren
    Infrastructure Architect

  • Wednesday, August 22, 2012 8:06 PM
     
     
    Ya that was my first thought, but no profile exists.  I.e. the path in $profile doesn't exist.