A lousy title perhaps, but I just don't know the word for what I want to do (and if I even should attempt to do it that way).
I'd like to write a script where I via a variable can set switches for some commands.
Like for example, I want to do:
OR
depending on a variable.
I could break it apart and have some sort of if-then-else, but the code in the foreach is the same for both variants making me want to do something like
having the switch argument dynamic.
Can I do it like that in some way. And also, should I do it like that?
I'd like to write a script where I via a variable can set switches for some commands.
Like for example, I want to do:
Code:
foreach ($file in Get-ChildItem $folder.Path)
Code:
foreach ($file in Get-ChildItem $folder.Path -recurse)
I could break it apart and have some sort of if-then-else, but the code in the foreach is the same for both variants making me want to do something like
Code:
foreach ($file in Get-ChildItem $folder.Path $recurse)
Can I do it like that in some way. And also, should I do it like that?