powershell variable, pipeline variable, $ everything

Variable

  • prefix name with ‘$’ symbol
  • $v = “hello” and use it as $v everywhere
  • not when you use Set-Variable
    • Set-Variable -Name v -Value “hello”
  • no need to specify type if required [int]$number = 1
  • Get-Variable lists all variables defined
  • Pipeline variable $_
    • implicit object in the pipeline
    • Get-Service | Where-Object {$_.DisplayName -like “*Microsoft*”}
    • Get-Service | %{$_.DisplayName}
  • $? – success status of last command
  • $Args – arguments of a function
  • Special characters in variable
    • The name will have to be enclosed in {}
    • for example if  variable name contains #, an object has EMP# as a member, use  $emp.{EMP#} to access the variable
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s