PowerShell Statements

Conditional Statements.

   if .. else        Conditionally perform a command
   Switch            Multiple if statements

Looping statements:

   Do .. while       Loop while a condition is True
   ForEach           Loop through each item in a collection
   For               Loop through items that match a condition
   While             Loop while a condition is True

Flow control statements:

   break             Halt execution of the current loop.
   continue          Return to top of a program loop immediately.

   return value      Return a value from a script/function
   Exit errorlevel   Return an error code from the current script.

Examples

Replace the text in the variable $MyDemoVar:

PS C:\> if ($MyDemoVar -like "*SS64*") {$MyDemoVar -replace "SS64", "Demonstration Example"}

“Be kind, for everyone you meet is fighting a hard battle” ~ Ian Maclaren

Related PowerShell Cmdlets:

Parameters - Command Line Parameters param() and $args[]
CommonParameters - cmdlet parameters.


 
Copyright © SS64.com 1999-2019
Some rights reserved