Friday, January 7, 2011

Working with PowerShell “cmdlets”

Pronounced “Command-lets”, cmdlets are a great way of scripting Administrative tasks in SharePoint 2010. I personally feel that I was missing such a tool till last year working with MOSS 2007. But with cmdlets, it looks extremely promising that Microsoft has ultimately provided the SharePoint Administrators – a single platform to script their tasks and run commands remotely/locally.

Recently, I was trying to look into these cmdlets and here are some quick view into some of the most basic ones.

Interestingly, these cmdlets are in a format that resembles the verb-noun pair. The noun generally starting with a “SP” for all SharePoint cmdlets.

#1. Get-SPContentDatabase: This gives you a list of all the Content DBs in your farm, with information on ID, Name, Server and Site count.

Okay, now you must be thinking that I am going to get nasty by listing down all these cmdlets, uhh… you are definitely wrong.

Instead, I just figured-out how to retrieve a list of such SP cmdlets and also how to pull more information about each of them.

Get-Command and Get-Help can be really handy for anyone starting on these. Here’s an example of how to use the Get-Command.

Get-Command –PSSnapin “Microsoft.SharePoint.PowerShell”

Further-more, if you start creating your own scripts, you would also need to start using these two very often:

> Measure-Command: This gives you the cmdlets execution time.

> Trace-Command: gives you the ability for debugging short scripts.

Technorati Tags: ,,