Created
January 14, 2025 13:27
-
-
Save steviecoaster/13a23bdf60ae25c042d704ed48804420 to your computer and use it in GitHub Desktop.
Use scriptblocks as evaluation in a PowerShell switch statement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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