Skip to content

Instantly share code, notes, and snippets.

@rjmholt
Created April 19, 2021 17:51
Show Gist options
  • Save rjmholt/0be4bf0de6f6a08a9ecb848d55f7c0bc to your computer and use it in GitHub Desktop.
Save rjmholt/0be4bf0de6f6a08a9ecb848d55f7c0bc to your computer and use it in GitHub Desktop.
Conditional array example
# Example 1
$statArgs = @(
'-c'
if ($IsMacOS) { '%A' } else { '%a' }
'/etc/passwd'
)
# Also note that this is an example of array splatting with a native command
/bin/stat @statArgs
# Example 2
# Naturally this is a bit contrived, since you could do gci ./baseCsvs,./extraCsvs with some extra logic
$csvsToCopy = @(
Get-ChildItem -Path ./baseCsvs -Recurse -Pattern '*.csv'
if (Test-Path -Path ./extraCsvs) { Get-ChildItem -Path ./extraCsvs -Recurse -Pattern '*.csv' }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment