Difference between revisions of "Power Shell"

Jump to navigation Jump to search
(→‎Variables: Added NULL stuff)
(Update table formatting)
Line 32: Line 32:
<source lang="powershell"> get-host | select version </source>.
<source lang="powershell"> get-host | select version </source>.
However, if you might have installed something other than the normal RTM or GA release version you'll need to the registry key <code>HKLM\Software\Microsoft\PowerShell\1</code>, which will have the following values of interest...
However, if you might have installed something other than the normal RTM or GA release version you'll need to the registry key <code>HKLM\Software\Microsoft\PowerShell\1</code>, which will have the following values of interest...
{|cellpadding="1" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-
! Value                !! Data                                !! Meaning
! Value                !! Data                                !! Meaning
|-
|-
Line 56: Line 56:


== Useful One-Liners ==
== Useful One-Liners ==
{|cellpadding="1" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-  
! Command              !! Description  
! Command              !! Description  
|-
|-
Line 80: Line 80:


'''Data types'''
'''Data types'''
{|cellpadding="1" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-  
! Notation                      !! Data Type
! Notation                      !! Data Type
|-
|-
Line 249: Line 249:


=== Escape Characters ===
=== Escape Characters ===
{|cellpadding="1" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-  
!  Text              !! Description
!  Text              !! Description
|-
|-
Line 373: Line 373:


Useful formatting examples...
Useful formatting examples...
{|cellpadding="2" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-  
! uFormat Specifier                            !! Example
! uFormat Specifier                            !! Example
|-
|-
Line 388: Line 388:


Useful formatting examples...
Useful formatting examples...
{|cellpadding="2" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-  
! ToString Method Specifier          !! UK-Centric Example Output
! ToString Method Specifier          !! UK-Centric Example Output
|-
|-
Line 427: Line 427:
=== Macros / Built-in Variables ===
=== Macros / Built-in Variables ===


{|cellpadding="4" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-  
! Variable                !! Description
! Variable                !! Description
|-
|-
Line 472: Line 472:
== Conditional Operators ==
== Conditional Operators ==
== Comparison ==
== Comparison ==
{|cellpadding="1" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-  
!  Operator          !! Description
!  Operator          !! Description
|-
|-
Line 502: Line 502:


=== Logic ===
=== Logic ===
{|cellpadding="1" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-  
!  Operator            !! Description
!  Operator            !! Description
|-
|-
Line 713: Line 713:
To control how a script behaves as a result of an exception, modify the <code> $ErrorActionPreference </code> variable, if required.  '''In the default continue mode, an error will output to the screen, then the script will continue.  By outputting the error to the screen PowerShell CmdLets consider the exception to have been handled!  If you want the opportunity to <code>catch</code> or <code>trap</code> you must append <code>-ErrorAction:Stop</code> to the CmdLet you expect might fail.'''
To control how a script behaves as a result of an exception, modify the <code> $ErrorActionPreference </code> variable, if required.  '''In the default continue mode, an error will output to the screen, then the script will continue.  By outputting the error to the screen PowerShell CmdLets consider the exception to have been handled!  If you want the opportunity to <code>catch</code> or <code>trap</code> you must append <code>-ErrorAction:Stop</code> to the CmdLet you expect might fail.'''


{|cellpadding="1" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-  
! Value            !! Effect
! Value            !! Effect
|-
|-
Line 729: Line 729:
Provides a list of recent errors experienced - which can be invaluable for properly identifying and investigating errors.  The object is the same as found in a pipeline when an exception has occurred.
Provides a list of recent errors experienced - which can be invaluable for properly identifying and investigating errors.  The object is the same as found in a pipeline when an exception has occurred.


{|cellpadding="1" cellspacing="0" border="1"
{|class="vwikitable"
|- style="background-color:#bbddff;"
|-  
! Property                                    !! Description                              !! Example (VC login error)
! Property                                    !! Description                              !! Example (VC login error)
|-
|-