DaveWentzel.com            All Things Data

Console

When working with the console their are two "modes"...expression mode and command mode.  Consider the following:
 
 
The first command is evaluating "1+1" as a string and echo'ing it back to you.  It is using expression mode for evaluation.  Here are the rules:
  • When you want to override expression place your expression inside parens. 
  • PS uses expression mode when the command begins with:
    • a number
    • $ (a variable)
    • " (quotation marks, see screenshot above)
    • a dot followed by a number
  • PS uses command mode when the line begins with:
    • alphabetic character
    • . (dot space...this notation is used to execute a .ps1 file in the current folder). 
    • .a (dot alpha...here the assumption is we are manipulating a .NET object).
    • &
      • whatever follows the & is considered a command.  For instance, I could create a "poor man's alias".  Consider this example where I create a variable to hold a command that I wish to execute:

 

Powershell -PSConsoleFile name

loads a given console file (.psc1).  To save your current session to a .psc1 file use export-console  which generates an xml file. 

get-pssnapin

shows you which snapins are loaded

PowerShell Home

 

Add new comment