Skip to content

Instantly share code, notes, and snippets.

@steviecoaster
Created January 14, 2025 13:27
Show Gist options
  • Save steviecoaster/13a23bdf60ae25c042d704ed48804420 to your computer and use it in GitHub Desktop.
Save steviecoaster/13a23bdf60ae25c042d704ed48804420 to your computer and use it in GitHub Desktop.
Use scriptblocks as evaluation in a PowerShell switch statement
$var = @{A = 10; B = 'abc'}
foreach ($key in $var.Keys) {
switch ($var[$key].GetType()) {
{ $_ -eq [int32] } { "$key + 10 = $($var[$key] + 10)" }
{ $_ -eq [string] } { "$key = $($var[$key])" }
}
}
# Output
A + 10 = 20
B = abc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment