Skip to content

Instantly share code, notes, and snippets.

@Sambardo
Created February 28, 2018 19:24
Show Gist options
  • Save Sambardo/3b85af2a8fce8858aa97834bdc5ac9c8 to your computer and use it in GitHub Desktop.
Save Sambardo/3b85af2a8fce8858aa97834bdc5ac9c8 to your computer and use it in GitHub Desktop.
use the built in loop of the switch, no foreach required
$nums = 1..15
Switch($nums)
{
{$_ -lt 5} {write-host "$_ is less than 5!" -ForegroundColor Magenta}
{$_ -lt 10} {write-host "$_ is less than 10!" -ForegroundColor green}
{$_ -lt 15} {write-host "$_ is less than 15!" -ForegroundColor cyan}
default {write-host "$_ is greater than or equal to 15" -ForegroundColor yellow}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment