r/PowerShell • u/mistajingsta • Jul 02 '20
Chapter 8 - Switch Statements
https://youtu.be/JcrLNVwplAI2
u/jsiii2010 Jul 02 '20 edited Jul 02 '20
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!
1
1
u/NoncarbonatedClack Jul 02 '20
How did I NOT see this is a series! Starting chapter 1.
3
u/mistajingsta Jul 02 '20
I will try to make it to the end of this book, but be patient. :D I think I will be spreading the load to some azure sentinel too.
3
u/NoncarbonatedClack Jul 02 '20
Oh sweet. As someone trying to discover and learn more on PowerShell right now, I appreciate the work you're putting in!
1
1
1
1
1
7
u/scross4565 Jul 02 '20
Your channel and your work is simply phenomenal ! Cant thank you enough for your hard work