Powershell is a new addition to SharePoint 2010 – and to spend a few hours becoming familiar with the PowerShell commands will definitely save you a minute or 10 now and then in your daily life with SharePoint 2010. In this first post, we will get in touch with PowerShell and start out with a few “Hello World of PowerShell for Sharepoint” scripts, and the later – if I hopefully find the time – I wil make a deeper dive into this world. So let’s hit it – let’s SharePoint….!!!!
First of all we need a fancy command prompt – to get it click Start | Run and in the box type cmd and click OK – and BAM – you have a nice command box ready for use. To make it a powershell command type powershell and press enter

To communicate with the host(i.e making the prompt write information for you) you have to use the command Write-Host. So typing Write-Host Hello World at the prompt will make it send you a message. Actually you can format it very basically. –foregroundcolor green will eg. Make the text green and you also have a backgroundcolor you can play around with. If ever in doubt what parameters a certain powershell-command takes write get-help and the name of the help function will help you.

This is very basically what you needs of information of PowerShell to get rolling with PowerShell for SharePoint 2010 – so let’s hit it and get some information regarding SharePoint in the box. To get to that point we need some extra information regarding Powershell – and that is that the functionality you can use is depending on what snap-ins you have loaded. A snap-in is no more than a bunch of functionality in one package – and we need to load the ones for SharePoint – to do that type Add-PSSnapin Microsoft.SharePoint.PowerShell at the command prompt.
To get a list of commands available type Get-command and nearly everything which includes an SP will be sharepoint-related. However, this is quite a few –so to get a document with all of them, type get-command –pssnapin Microsoft.sharepoint.powershell > c:\commands.txt and a nice notepad-doc will be created for you at the c-drive including all of the commands available.
A lot of gets and sets are present – so try to write Get-SPWebApplication at the prompt – and notice that a list of Web Applications with DicplayName and Urls from the farm will appear. Nice And easy J
Basically there are two important kind of PowerShell commands for SharePoint – the ones starting with GET-SP – which gets you something and NEW-SP which creates something. If you want to create a new WebApplication this can be done with the New-SPWebApplication command – so try to type Get-Help New-SPWebApplication at the command prompt to see what is needed for a new Web Application – the following is returned

So typing New-SPWebApplication –name “Qwert Intranet” –ApplicationPool “Qwert Intranet” –ApplicationPoolAccount q\administrator –DatabaseName SharePoint_Qwert_Content_Intranet –HostHeader Intranet.qwert.dk –port 80 –url http://intranet.qwert.dk
After thinking a while – your web application is created – confirm by writing Get-SPWebApplication at the command prompt and your new web application will appear.
Deleting the web application is providing by Remove-SPWebApplication – try typing get-help Remove-SPWebApplication to read more about the properties – the command below deletes your web application – note that you have to confirm the action.

A final Get-SPWebApplication will confirm the deletion.