Created
April 19, 2021 17:51
-
-
Save rjmholt/0be4bf0de6f6a08a9ecb848d55f7c0bc to your computer and use it in GitHub Desktop.
Conditional array example
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
# 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