Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jcefoli/c8b5b117f410e8f6caa5516d60c93dae to your computer and use it in GitHub Desktop.
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
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