0

I've bundled a Chocolatey installer into PowerShell: My script calls a function for the installation process. The user is supposed to run .\install.ps1 in PowerShell. If the package already is installed the output is similar to:

<Packagename> already installed.
Use --force to reinstall, specify a version to install, or try upgrade.

Ok, so the user should think that .\install.ps1 --force will do the trick. Unfortunately, I have found no way for PowerShell to accept double dashes (--), so I'm thinking about rewriting the warning message from Chocolatey so it outputs -force instead of --force:

<Packagename> already installed.
Use -force to reinstall, specify a version to install, or try upgrade.

My setup.ps1 file is similar to:

Install-App <Packagename + parameters>

The function my script is calling is similar to:

function Install-App
{
    //..code ommited..
    $chocoCommand = "choco install <Packagename + parameters>"
    iex $chocoCommand
}

I've been thinking about try/catch, but haven't figured it out quite yet.

Any suggestions?

Best regards

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188

2 Answers2

0

You should try --% just before any arguments are passed.

Taken from https://chocolatey.org/docs/commands-reference#how-to-pass-options-switches

ferventcoder
  • 11,952
  • 3
  • 57
  • 90
0

I solved this by doing a foreach on $args:

foreach($arg in $args)
{
    if($arg -eq "--force" -Or $arg -eq "-force")
    {
        $forceParameter = "--force"
    }
}

And further passing this to my PowerShell command

MyCustomCommand -forceParameter $forceParameter

Thanks for the help!