Saturday, March 12, 2011

SP 2010 Power Shell - The term 'Get-SPSite' is not recognized as the name of a cmdlet

You may see error while executing sharepoint commandlets on your machine. For example if you are trying to execute a simple commandlet as:
Get-SPSite
You may see below error:
The term 'Get-SPSite' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:11
+ Get-SPSite <<<<
+ CategoryInfo : ObjectNotFound: (Get-SPSite:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException


To resolve this error just run following command to your powershell snapin:
Add-PSSnapin Microsoft.SharePoint.Powershell

2 comments:

  1. Iam getting same error.My coding is as follows

    protected void btnReadOnly_Click(object sender, EventArgs e)
    {

    try
    {
    txtOutPut.Text="";
    txtOutPut.Text = RunScript(txtScript.Text);


    }
    catch (Exception error)
    {
    txtOutPut.Text += String.Format("\r\nError in script : {0}\r\n", error.Message);
    }
    }
    private string RunScript(string scriptText)
    {

    Runspace runspace = RunspaceFactory.CreateRunspace();
    runspace.Open();
    Pipeline pipeline = runspace.CreatePipeline();
    pipeline.Commands.AddScript(scriptText);
    pipeline.Commands.Add("Out-String");
    Collection results = pipeline.Invoke();
    runspace.Close();
    StringBuilder stringBuilder = new StringBuilder();
    foreach (PSObject obj in results)
    {
    stringBuilder.AppendLine(obj.ToString());
    }

    return stringBuilder.ToString();
    }

    ReplyDelete