Wednesday 6 July 2011

Powershell command to access Microsoft.SharePoint assembly does not work

I wanted to list the set of resource measures on the SharePoint environment that I am working on. To get the list of resource measures we can use powershell, using the command
[Microsoft.SharePoint.Administration.SPUserCodeService]::Local.ResourceMeasures
I encountered the following error in the console.
Unable to find type [Microsoft.SharePoint.Administration.SPUserCodeService]: make sure that the assembly containing this type is loaded.
At line:1 char:56
+ [Microsoft.SharePoint.Administration.SPUserCodeService] <<<< ::Local.ResourceMeasures + CategoryInfo : InvalidOperation: (Microsoft.Share...UserCodeService:String) [], RuntimeException + FullyQualifiedErrorId : TypeNotFound


Solved:
The problem was because SharePoint powershell snap in was not loaded.
The command to load the SharePoint powershell snap in is as follows. We need to just run this command in the powershell command prompt.
Add-PSSnapin Microsoft.SharePoint.Powershell

2 comments:

  1. When trying to add that as a snapin, I get the following error:

    add-pssnapin : No snap-ins have been registered for Windows PowerShell version 5.
    At line:1 char:1
    + add-pssnapin microsoft.sharepoint.powershell

    I am running from a Sharepoint Online Management Shell
    I am running this shell as an administrator
    My get-executionpolicy returns "Unrestricted"

    Why is this not working?

    ReplyDelete
  2. When trying to add that as a snapin, I get the following error:

    add-pssnapin : No snap-ins have been registered for Windows PowerShell version 5.
    At line:1 char:1
    + add-pssnapin microsoft.sharepoint.powershell

    I am running from a Sharepoint Online Management Shell
    I am running this shell as an administrator
    My get-executionpolicy returns "Unrestricted"

    Why is this not working?

    ReplyDelete