Created
July 23, 2024 17:52
-
-
Save jcefoli/c8b5b117f410e8f6caa5516d60c93dae to your computer and use it in GitHub Desktop.
Process a multidimensional array with switches based on environment flags and data within the array
This file contains 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
param( | |
[switch]$dev, | |
[switch]$qa, | |
[switch]$prod | |
) | |
# Define the multidimensional array | |
$apps = @( | |
@{ stack = 'dev'; appName = "foo"; username = 'foo1'; password = "passy1" } | |
@{ stack = 'dev'; appName = "foo-dev1"; username = 'foo1'; password = "passy1" } | |
@{ stack = 'dev'; appName = "foo-dev2"; username = 'foo1'; password = "passy1" } | |
@{ stack = 'dev'; appName = "foo-dev3"; username = 'foo1'; password = "passy1" } | |
@{ stack = 'qa'; appName = "baz"; username = 'baz1'; password = "passy3" } | |
@{ stack = 'prod'; appName = "bar"; username = 'bar1'; password = "passy2" } | |
) | |
# Determine which stack to process based on the switch provided | |
$selectedStack = $dev ? 'dev' : ($qa ? 'qa' : ($prod ? 'prod' : $null)) | |
if (-not $selectedStack) { | |
Write-Host "No valid stack switch was provided. Exiting the script." | |
exit | |
} | |
# Loop through the array of $apps | |
foreach ($app in $apps) { | |
# Check if the stack matches the selected switch | |
if ($app.stack -eq $selectedStack) { | |
Write-Host "Processing app: $($app.appName) in $($app.stack) environment." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment