In Powershell, I'm trying to make a list of files to be excluded from various commands that take exclusion parameters, e.g. Get-ChildItem.
The files I'm dealing with belong to various projects and represent sequential page numbers such that for a given project A, it would have files projA.1, projA.2, etc. I'd like to be able to make one list of page numbers (not files) to be excluded, but apply that list to multiple projects, so I feel like what I want to do is have an array of excluded page numbers that then get concatendated onto the project name and passed as an exclusion parameter. However, I don't know if there's a compact way to do this. Here's what I have so far:
# Source and destination projects with files named projA.1, projA.2,...,projA.n, etc.
$sourceProject = "projA"
$destProject = "projB"
# List of pages which will be excluded
$pageExclusions =@(
"1",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"35",
"36",
"37",
"38",
"40")
$sourceExclusions = @()
foreach($i in $pageExclusions){
$sourceExclusions = $sourceExclusions + ($sourceProject + "." + $i)
}
# ... later I will use $sourceExclusions as an exclude filter, e.g.:
Get-ChildItem projA.* -Exclude $sourceExclusions
# and I'd need to repeat the same for projB
In my code example, is there a compact notation to say "sourceExclusions is a new array such that is is the same length as $pageExclusions but each entry is the filename projA with the corresponding extension from $pageExclusions"?
Or, even better yet, is there a way to pass them both to an exclude parameter directly in a way it will interpret to result in $sourceExclusions.