About Me

Calgary, Alberta, Canada
Some know me as Phani, many know me as 'PK'… Mr.Perfect

Friday, November 5, 2010

Windows Powershell

Windows PowerShell is a command line utility that builds on top of the .NET Framework. In MOSS 2007 administrators used to use a command line utility stsadm.exe to run interactive commands. SharePoint foundation still installs stsadm.exe, to support backward compatibility with scripts migrating from earlier versions.

Microsoft forced administrators and developers to learn Windows PowerShell in SharePoint 2010. You can create scripts to create web application, site collection and what not. Deployment and configurations can be automated using PowerShell scripting.

Note: 1. MOSS 2007 deployment and configuration can be automated using STSADM.EXE and PowerShell too.
2. Administrators and developers must learn Windows PowerShell basics.


Windows PowerShell is an extensible scripting language and allows you to develop your own custom Windows PowerShell snap-ins. You can write powerful scripts against SharePoint Object Model. You can develop custom windows PowerShell Snap-ins.
  • Start Windows PowerShell console window.
  • start\All Programs\Windows PowerShell\Windows PowerShell
Over the last few years, Windows PowerShell scripting has begun to replace older DOS style batch files to manage and automate administrative tasks.

Windows PowerShell is based on reusable libraries containing functions known as cmdlets (pronounced "command lets"). 

For example, the built-in Windows PowerShell libraries provide a cmdlet named Get-Process, which returns a collection of objects representing the Windows processes running on the current machine.

Pipelining allows one cmdlet to return an object as input to another. You can author Windows PowerShell scripts. Scripts have *.ps1 extension. Local execution policy must be configured.

Execution Policy

By default, Windows PowerShell does not allow script to run. The SharePoint administrator must change execution policy to enable script execution.

Possible execution policy settings
  • restricted - scripts prohibited from execution (default option)
  • bypass - Scripts can be executed without user interaction (Developer mode)
  • unrestricted - Scripts can execute with user interaction.
SharePoint Powershell Snap in

SharePoint Foundation provides a specialized version of the Windows 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

Example : Get-SPWebApplication - Collection of webapplications in the current farm excluding SharePoint 2010 Central Administration web application.


Windows Powershell ISE

With the initial release of Windows PowerShell, administrators and developers used to write scripts with notepad. Windows PowerShell 2 provides a nice development environment for writing Windows PowerShell scripts named the ISE. it supports color-coding. Intellisense and debugging.

I will publish the development rig details in early next week and also step by step lab on Windows PowerShell scripting.


No comments:

Post a Comment