Friday, 4 January 2013

PowerShell Basic - Speical Character

Its very difficult to remember every syntax and what it refers to when you are working with myriad of languages.

Below are the useful basic Characters which you need when you work in Power Shell.

1. Single Line comment representation : #

Ex. # This is a single line comment 


2. Multiple Line comments representation: <# #>

Ex. <# This is a Multiple

           Line Comments #>

 

3.Declare a variable: $

Ex. $a=$null

 

4.Item inside for each loop or current pipeline object : $_

Ex. .... | Foreach {Write-Host $_}

 

5.Continue command on next line: `

Ex. Write-Host `

      "Hello World!!"

 

6.Where-Object shortcut : ?

Ex. .... |  1..5 | ? {Write-Host $_ % 2} # Here % represent mod

 

7.Not Shortcut : !

Ex.  $a=$null | if($a) {Write-Host "$a is not null"}

 

8.For each Shortcut: %

Ex. .... | % {Write-Host $_}

 

9. To catch the output of the command and pass it to the another command: |

Ex.  get-process | select-object -first 3


10. Declare Array: @()

Ex. $a= @("one" , "two" , "three")


11. Declare Hash table: @{}

Ex. $a= @{"1" = "one" ; "2" ="two" ; "3" ="three"} 


12. To specify a range: ..

Ex. 1..5 | 


Hope this help

Isha


 

 


No comments:

Post a Comment