Reputation: 6440
I have a cmdlet with the following defintion:
[CmdletBinding(DefaultParameterSetName="Path",
SupportsShouldProcess=$TRUE)]
param(
[parameter(Mandatory=$TRUE,Position=0)]
[String] $Pattern,
[parameter(Mandatory=$TRUE,Position=1)]
[String] [AllowEmptyString()] $Replacement,
[parameter(Mandatory=$TRUE,ParameterSetName="Path",
Position=2,ValueFromPipeline=$TRUE)]
[String[]] $Path,
[parameter(Mandatory=$TRUE,ParameterSetName="LiteralPath",
Position=2)]
[String[]] $LiteralPath,
[Switch] $CaseSensitive,
[Switch] $Multiline,
[Switch] $UnixText,
[Switch] $Overwrite,
[Switch] $Force,
[String] $Encoding="ASCII"
)
I put the cmdlet .ps1 file in the same folder as as a powershell script file that calls the cmdlet as following:
Invoke-Expression -Command .\Replace-FileString.ps1 "9595" "NewPort" "c:\temp" -Overwrite
However, when I execute my ps script, I get the following error:
Invoke-Expression : A positional parameter cannot be found that accepts argument '9595'. How can I make it work? Thanks.
Upvotes: 1
Views: 4576
Reputation: 54821
Try:
Invoke-Expression -Command '.\Replace-FileString.ps1 "9595" "NewPort" "c:\temp" -Overwrite'
Your command includes arguments that uses quotemarks, so PS thinks that your command is over and those are new arguments(not a part of the -Command paramter).
Upvotes: 2