Loading Sharepoint PowerShell Snapin

Environments like SharePoint Foundation add their own custom cmdlet library by installing a PowerShell Snap-in. When you install SharePoint Foundation, it installs its core PowerShell snap-in named Microsoft.SharePoint.PowerShell. However, you have to ensure that Microsoft.SharePoint.PowerShell is loaded before you begin to call its cmdlets.

Microsoft Foundation provides a specialized version of the PowerShell console known as the SharePoint 2010 Management Shell. You can launch the SharePoint 2010 Management Shell from a shortcut that SharePoint Foundation adds to the Windows Start menu> All Programs > Microsoft SharePoint 2010 Products > SharePoint 2010 Management Shell


The main difference between the standard PowerShell console window and the SharePoint 2010 Management Shell console has to do with what PowerShell providers get loaded automatically. More specifically, the SharePoint 2010 Management Shell automatically loads the SharePoint provider named Microsoft.SharePoint.PowerShell while the standard PowerShell console does not. In general, you cannot always rely on Microsoft.SharePoint.PowerShell being loaded automatically so you need to learn how to explicitly load it within a PowerShell script.

Let's say you have just launched the standard PowerShell console window and you attempt to execute one of the cmdlets built into SharePoint Foundation such as the cmdlets named Get-SPWebApplication. The call to this cmdlet will fail unless you have already loaded the SharePoint PowerShell snap-in named Microsoft.SharePoint.PowerShell. Before calling the Get-
SPWebApplication cmdlets, you need to load the SharePoint Foundation PowerShell snap-in using the Add-PSSnapin cmdlet .

Add-PSSnapin Microsoft.SharePoint.PowerShell

Windows Live Tags: Loading Sharepoint PowerShell Snap-in

Blogger Labels: Loading Sharepoint PowerShell Snap-in

Enabling PowerShell Integrated Scripting Environment (ISE) on Windows Server 2008

Windows Server 2008 or Windows Server 2008 R2 includes a powerful utility named PowerShell Integrated Scripting Environment(ISE).It allows to debug PowerShell Scripts in a very efficient manner.But unfortunately it doesn’t give intellisense support.

SharePoint Foundation installs the PowerShell runtime ,but does not automatically install the PowerShell ISE. You have to explicitly enable it by adding a windows feature

enabling ISE

Blogger Labels: PowerShell Integrated Scripting Environment(ISE),Enabling PowerShell Integrated Scripting Environment(ISE) on Windows Server 2008

Enabling PowerShell Integrated Scripting Environment (ISE) on Windows Server 2008

Windows Server 2008 or Windows Server 2008 R2 includes a powerful utility named PowerShell Integrated Scripting Environment(ISE).It allows to debug PowerShell Scripts in a very efficient manner.But unfortunately it doesn’t give intellisense support.

SharePoint Foundation installs the PowerShell runtime ,but does not automatically install the PowerShell ISE. You have to explicitly enable it by adding a windows feature

enabling ISE

Blogger Labels: PowerShell Integrated Scripting Environment(ISE),Enabling PoerShell Integrated Scripting Environment(ISE) on Windows Server 2008

Power Shell cmdlets and pipelining

PowerShell is based on reusable libraries containing functions known as cmdlets (pronounced command lets). Cmdlets have names which follow the convention of a common verb followed by a noun. For example, the built-in PowerShell libraries provide a cmdlet named Get-Process which returns a collection of objects representing the Windows processes running on the current machine.

PS D:\Users\Administrator> Get-Process

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
    400      45   217700     223408   461   299.30   5172 Acrobat
     80      10     1696       5188    72     0.03   5520 acrotray
     66       9     1632       4712    68     0.03   1780 Adobelm_Cleanup.0001
     66       9     1636       4672    68     0.03   6100 Adobelm_Cleanup.0001
     54       7     1104       3060    28     0.00   5176 Adobelmsvc
     41       4     1012       2508    15     0.00   1692 AESTSr64
     48       6     2136       4972    54     0.73   1680 conhost
     31       4      928       2392    22     0.00   4468 conhost

Pipelining in an important concept to understand when executing cmdlets. The basic idea is that every cmdlets returns an object or a collection of objects. Pipelining allows you to take the results of one cmdlets and pass it to a second cmdlet. The second cmdlets can run and then pass its results to a third cmdlets and so on. You create a pipeline by typing a sequence of cmdlets separated by the | (pipe) character.

cmdlet1 | cmdlet2 | cmdlet3

Example

if (dir | where {$_.length –gt 10kb}) {
“There were files longer than 10kb”
}

Blogger Labels: Pipelining in PowerShell,PowerShell cmdlets

Power Shell Common syntaxes

There are two common ways in which you can use PowerShell. First, you can execute commands interactively using the PowerShell console window. Second, you can write scripts to automate administration tasks.

Accessing PowerShell Console window

Start > All Programs > Accessories > Windows PowerShell > Windows PowerShell

Common Help

  • Use the “exit” keyword to exit the shell
  • Ctrl-C will interrupt the current task returning you to the prompt.
  • A command can be spread over multiple lines and the interpreter will prompt for additional input. The line continuation character is the back-quote ‘`’ (also called the back-tick).
  • Ctrl-C will interrupt the current task returning you to the prompt.
  • To get help about a command you can do “help command”. The help command by itself will give you a list of topics.
  • The help command supports wildcards so “help get-*” will return all of the commands that start with “get-”.
  • You can also get basic help on a command by doing “commandName -?” like “dir –?”

Variables in Power Shell

PS > $x= 5                
PS > echo $x
5

PS >

Arrays
PS > $x= Subhasis,Daniel, Mac
PS > echo $x[1]
Daniel

PS >

HashTable

PS > $h= @{a=1;b=2;c=3}
PS > echo $h
Name             Value

a                       1
b                       2
c                       3
Flow-control Statements:

These Statements can be used to iterate the user collections


if Statement:
if ($b –eq 15) { $a=13} else {$a=15}

The condition part of an if statement may also be a pipeline.


if (dir | where {$_.length –gt 10kb})

{
“There were files longer than 10kb”
}

while Loop:

$b=1; while ($b –lt 10) { echo $b }

for Loop:

for ($i=0; $i –lt 10; $i++)

{
echo $i
}

foreach Loop:

foreach ($i in 1..10)

{
$echo $i

}

Blogger Labels: PowerShell,Power Shell Common Syntaxes,PowerShell,PowerShell Control Statements,Power Shell and Sharepoint 2010,Administration using Power Shell and Sharepoint 2010,Start,Help,Ctrl,task,interpreter,continuation,Variables in PowerShell,Subhasis,HashTable in PowerShell,If Statement in PowerShell

Power Shell and SharePoint 2010

Why PowerShell ? Why Now ?

PowerShell was designed to do for Windows what the UNIX shells do for UNIX: provide a powerful, well-integrated command-line experience for the operation
system. Unfortunately since Windows is mostly managed through objects (WMI, COM and .NET) this required creating a new kind
of shell. So why create it now? As Windows moves off the desktop
and into server farms or application servers like print, DNS
and LDAP services, command-line automation becomes a
fundamental requirement.

PowerShell is freely available through the Microsoft Windows Update Service packaged as an optional update for Windows XP SP2, Windows Vista and Windows Server 2003. It is also included with Windows Server 2008 as an optional component.

In Sharepoint 2007,Farm Administrators used STSADM.EXE to do the administrative tasks. SharePoint Foundation still installs STSADM.EXE but it is primarily included to support backwards compatibility with scripts migrating from earlier versions.

PowerShell is something i was always love to have in the production farm.In MOSS 2007,there were many things which can be done through object model easily,can’t done through STSADM.EXE.Sharepoint  2010 is the first version to directly support PowerShell.In PowerShell, You can directly access Sharepoint object model through the codes in the console window. Nice …isn’t it ?

I started exploring PowerShell long back. In next couple of posts, i will try to provide comprehensive list of operations you need to know to get your hands dirty on PowerShell.

Installing Sharepoint 2010 beta

The above article describes step by step proceedure for installing sharepoint 2010 on windows 7.

Only thing missing is installing Visual studio 2010. Install visual studio 2010 first and then proceed towards installation of sharepoint 2010.
 
 
The above article describes step by step proceedure for installation of sharepoint 2010 on windows server 2008 and also installion and configutaion of SQL server 2008.
 
Errors while running Sharepoint 2010 beta configuration wizard

There will be two errors most likely to come while configuration wizard is running.
1. Error in step 5

 

Failed to register SharePoint services.

An exception of type System.TypeLoadException was thrown. Additional exception information: Could not load type 'Microsoft.Office.Server.Search.Administration.SearchWebServiceManagerService' from assembly 'Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C'.

System.TypeLoadException: Could not load type 'Microsoft.Office.Server.Search.Administration.SearchWebServiceManagerService' from assembly 'Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C'.

at System.RuntimeTypeHandle._GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName)

at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)

at System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)

at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)

at Microsoft.SharePoint.PostSetupConfiguration.ReflectionHelper.InvokeConstructor(String assemblyQualifiedName, Type[] constructorSignature, Object[] constructorParameters)

at Microsoft.SharePoint.PostSetupConfiguration.TaskCommon.ReflectionHelperInvokeConstructor(String assemblyQualifiedName, Type[] constructorSignature, Object[] constructorParameters, TaskBase task)

at Microsoft.SharePoint.PostSetupConfiguration.ServicesTask.InvokeServiceConstructor(String serviceRegistryKeyName, String solutionIdRegistryName, String serviceNameRegistryName, Type[] constructorSignature, Object[] constructorParameters)

at Microsoft.SharePoint.PostSetupConfiguration.ServicesTask.InstallServiceInConfigDB(Boolean provisionTheServiceToo, String serviceRegistryKeyName)

at Microsoft.SharePoint.PostSetupConfiguration.ServicesTask.InstallServices(Boolean provisionTheServicesToo)

at Microsoft.SharePoint.PostSetupConfiguration.ServicesTask.Run()

at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()
----------------------------------------------------------------------------------------------------------------------------------------------
This error can be removed by removing the following registry keys

Removing the following registry keys fixed the problem: 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\Services\Microsoft.Office.Server.Search.Administration.SearchWebServiceManagerService]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\ServiceProxies\Microsoft.Office.Server.Search.Administration.SearchWebServiceManagerServiceProxy]

2. Error in step 8
 

Failed to create sample data.

An exception of type Microsoft.Office.Server.UserProfiles.UserProfileException was thrown. Additional exception information: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+msbin1). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: ....



This error can be removed by installing the following hotfix

 http://go.microsoft.com/fwlink/?LinkID=166231