1

This is my script which is working fine.

$include = @(
    'File.M*'
    'ABC.M*' 
    'XYZ.M*'
)

At the end there is .M*. Is there anyway that I can simply use the common .M* outside of the bracket? Something like this:

 $include= @((
    "File"
    "ABC" 
    "XYZ"
    )+.M*)
1
  • nope. each item in the array of patterns must be complete in itself. Commented Jul 12, 2021 at 6:56

1 Answer 1

5

Not exactly like that, but you could do

$include = @(
    'File'
    'ABC' 
    'XYZ'
) | ForEach-Object {$_ + ".M*"}

and get the same thing

File.M*
ABC.M* 
XYZ.M*

Another way would be to use -replace and regex.

$include = @(
    'File'
    'ABC' 
    'XYZ'
) -replace '$', '.M*'

Note: $ is the position at the end of each line

Sign up to request clarification or add additional context in comments.

1 Comment

Loving the regex solution as much as hating the loop solution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.