Tuesday, March 11, 2014
Take your babysteps towards Powershell.
PowerShell everyone is talking about it how do I start?
In our current organization we do not do much of PowerShell as its restricted to use, but we cannot deny the effect this magnetic tool has on us, we all as SharePoint admins would love to have our hands on the PowerShell and how do we begin.
let’s start with the windows PowerShell commands to an idea of the syntax,
You can refer to http://www.microsoft.com/powershell for hell lot of information like webcasts/ wiki / downloads.
You need minimum pre-requisite for installation .net framework 2.0
Some interesting stuff
· you can execute DOS commands like dir, cls in PowerShell it works just like it should in regular DOS
· you can get mathematical calculations from PowerShell like type 2+2 and enter or 2*5/2*4
· The real powershell commands begin with a verb and second part is a noun, example: Get-Help; Get-Command
· Get- Command will list all the commands in powershell, also note commands in powershell are listed as Comma lets.
· Suppose you need to execute a command and you’re not sure how the syntax will be you can use get help
So use Get-Help Get-Commands ( assuming get-commands is the option you need help with)
That will list the syntax expected.
Also try Get-Help Get-Commands examples – this will list down the examples as well so you can compare and type.
Also try Get-Help Get-Commands detailed – this will give details and examples both.
· To copy a command in powershell select the command and right click, to paste copied command in powershell just right click.
· All operators by default do case insensitive comparison. If you specifically case sensitive comparisons add “c” to the operator example –ceq – case sensitive equality.
Working with windows PowerShell scripts
The commands are similar to Unix but one thing you need to know is that the output is treated as objects.
· In PowerShell setlocation- c:\scripts ( changes the location )
· You can save files as extension .ps or ps1 also commands can be saved in a .bat file and executed from windows explorer.
· The variables are created beginning with $
$colorarray = “Red” , “Green”, “Blue”, “Orange”
For each ($col in $colorarray )