MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/PowerShell/comments/hjt6z2/chapter_8_switch_statements/fwpmpge/?context=3
r/PowerShell • u/mistajingsta • Jul 02 '20
19 comments sorted by
View all comments
2
Switch is the Thor of powershell commands. Notes from Windows Powershell in Action.
switch -wildcard ('abc') {a* {"a*: $_"} *c {"*c: $_"}} switch -regex ('abc') {'(^a)(.*$)' {$matches}} switch (8) { {$_ -gt 3} {'greater than three'} {$_ -gt 7} {'greater than 7'} } switch(1..6) { {$_ % 2} {"Odd $_"; continue} 4 {"FOUR $_"} default {"Even $_"} } switch -wildcard (Get-ChildItem c:\windows) { *.dll {$dll++} *.txt {$txt++} *.log {$log++} } "dll $dll txt $txt log $log" switch ($options){ '-a' { $a=$true } '-b' { [void] $switch.MoveNext(); $b= $switch.Current } '-c' { $c=$true } '-d' { $d=$true } }
2 u/mistajingsta Jul 02 '20 switch -wildcard ('abc') {a* {"a*: $"} *c {"*c: $"}}switch -regex ('abc') {'(a)(.*$)' {$matches}}switch (8) { {$_ -gt 3} {'greater than three'} {$_ -gt 7} {'greater than 7'} }switch(1..6) { {$_ % 2} {"Odd $"; continue} 4 {"FOUR $"} default {"Even $_"} }switch -wildcard (Get-ChildItem c:\windows) { *.dll {$dll++} *.txt {$txt++} *.log {$log++} } "dll $dll txt $txt log $log"switch ($options){ '-a' { $a=$true } '-b' { [void] $switch.MoveNext(); $b= $switch.Current } '-c' { $c=$true } '-d' { $d=$true } }Ill add that to the doc!
switch -wildcard ('abc') {a* {"a*: $"} *c {"*c: $"}}switch -regex ('abc') {'(a)(.*$)' {$matches}}switch (8) { {$_ -gt 3} {'greater than three'} {$_ -gt 7} {'greater than 7'} }switch(1..6) { {$_ % 2} {"Odd $"; continue} 4 {"FOUR $"} default {"Even $_"} }switch -wildcard (Get-ChildItem c:\windows) { *.dll {$dll++} *.txt {$txt++} *.log {$log++} } "dll $dll txt $txt log $log"switch ($options){ '-a' { $a=$true } '-b' { [void] $switch.MoveNext(); $b= $switch.Current } '-c' { $c=$true } '-d' { $d=$true } }
switch -wildcard ('abc') {a* {"a*: $"} *c {"*c: $"}}
switch -regex ('abc') {'(a)(.*$)' {$matches}}
switch (8) { {$_ -gt 3} {'greater than three'} {$_ -gt 7} {'greater than 7'} }
switch(1..6) { {$_ % 2} {"Odd $"; continue} 4 {"FOUR $"} default {"Even $_"} }
switch -wildcard (Get-ChildItem c:\windows) { *.dll {$dll++} *.txt {$txt++} *.log {$log++} } "dll $dll txt $txt log $log"
switch ($options){ '-a' { $a=$true } '-b' { [void] $switch.MoveNext(); $b= $switch.Current } '-c' { $c=$true } '-d' { $d=$true } }
Ill add that to the doc!
2
u/jsiii2010 Jul 02 '20 edited Jul 02 '20
Switch is the Thor of powershell commands. Notes from Windows Powershell in Action.