r/PowerShell • • Jul 02 '20

Chapter 8 - Switch Statements

https://youtu.be/JcrLNVwplAI
119 Upvotes

19 comments sorted by

7

u/scross4565 Jul 02 '20

Your channel and your work is simply phenomenal ! Cant thank you enough for your hard work

5

u/mistajingsta Jul 02 '20

That means a lot!

2

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

u/[deleted] Jul 02 '20

Great work. Wish i had this before I purchased Plurasight.

2

u/mistajingsta Jul 02 '20

That is a great compliment !

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

u/senorezi Jul 02 '20

Awesome man!

1

u/mistajingsta Jul 02 '20

Thank you.

1

u/Mourne84 Jul 02 '20

Thanks mate, am surely going to follow this! Great work!

1

u/mistajingsta Jul 02 '20

Thank you for your kind words.

1

u/saleazer Jul 02 '20

Subscribed, thanks!!

1

u/mistajingsta Jul 03 '20

Thank you.

1

u/[deleted] Jul 02 '20

You're doing a great job! Very well done!

1

u/mistajingsta Jul 03 '20

Thank you for your kind words.

1

u/killiandw Jul 03 '20

Never knew about switch thanks

1

u/mistajingsta Jul 03 '20

Switch is a-maz-ing.