I have a simple script to call select-string for a specific file extension. I want to optionally provide other select-string params via script args.
my script findm.ps1
# simplified version to show error
select-string *.m -pattern $args[0] $args[1]
when I type findm.ps1 someFileName -List
I get the following error
Select-String : A positional parameter cannot be found that accepts argument '-List'.
typing the following form the cmd line works fine
select-string *.m -pattern "someFileName" -List
Thanks in advance
jra
The -List is being interpreted as a string (not an argument) by the parser, that needs to be associated with an argument.
Mike was close, but you need to reparse it as a powershell expression after you build your command string like this: