1

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.

1 Answer 1

2

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).

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.