Raghav
Raghav

Reputation: 3078

How do I pass parameters to the installer in a Chocolatey package?

I created a package from an MSI. However, I need to pass in custom parameters.

/i SERVER='xx.yyy.com

Here are the few things I tried by reading the choco command spec, but none worked.

> choco install foo -y --params "SERVER='xx.yyy.com'"
> choco install foo -y --params "SERVER=xx.yyy.com"
> choco install foo -y --params "SERVER= xx.yyy.com"

How do I pass the install options to the installer?

Upvotes: 17

Views: 27303

Answers (3)

vii
vii

Reputation: 523

Addition: Usage of the --param argument in PowerShell variables to pass to the installer, e.g.

choco install vscode $ParVar

This does only work when you include an equal sign = after --params ... (instead of a whitespace). Most package documentations show it without equal sign! While this is not a problem for direct execution, it fails when passing the parameters via a variable.

Proof for VS Code:

Without equal sign:

Proceeding Code
  1. VS Code Chocolatey Documentation: | choco install vscode --params "/NoDesktopIcon /NoQuicklaunchIcon"
  2. Copy to variable: | $ParVar = '--params "/NoDesktopIcon /NoQuicklaunchIcon"'
    Pay attention to single and double-quotes (see other answers).
  3. Execution (-> error): | choco install vscode $ParVar
    Chocolatey params error in PowerShell

With equal sign:

Proceeding Code
2. Copy to variable: $ParVar = '--params="/NoDesktopIcon /NoQuicklaunchIcon"'
Pay attention to = sign after params
3. Execution (-> success): choco install vscode $ParVar
Successfull chocolatey installation

-> This can be used in all packages which need params arguments with double-quotes. I tested this with several packages.

I utilize this approach to build up key:value dictionaries of a lot of apps which I then batch install on new machines.

Upvotes: 1

spechter
spechter

Reputation: 2368

I found information on setting a value into a Choco package parameter quite hard to find!

choco install -h isn't much help.

As a simple example of setting a value for a package parameter (as opposed to an MSI parameter - which is quite different), here is a simple, workable example:

choco install python2 --package-parameters='"/InstallDir:D:\Python2"'

"/InstallDir" is documented as a package parameter for the "python2" Choco package.

Note that there are a few alias for "--package-parameters", the shortest being "--params" if you like to save typing.

Note also the use of colon, NOT "=", where the value is assigned.

If you need spaces in the value, surround the value with extra pairs of double quotes - i.e. four new characters required.

... I have asked on the Choco forums to improve the documentation.

Upvotes: 6

ferventcoder
ferventcoder

Reputation: 12621

If you are passing to the native installer, please use --install-arguments and not --package-parameters.

https://chocolatey.org/docs/commands-install#options-and-switches

 --ia, --installargs, --installarguments, --install-arguments=VALUE
 InstallArguments - Install Arguments to pass to the native installer in 
   the package. Defaults to unspecified.

-o, --override, --overrideargs, --overridearguments, --override-arguments
 OverrideArguments - Should install arguments be used exclusively without 
   appending to current package passed arguments? Defaults to false.

 --params, --parameters, --pkgparameters, --packageparameters, --package-parameters=VALUE
 PackageParameters - Parameters to pass to the package. Defaults to 
   unspecified.

Additionally, you may want to explore the documentation on how to pass options and switches - https://chocolatey.org/docs/commands-reference#how-to-pass-options-switches:

  • Quote Values: When you need to quote an entire argument, such as when using spaces, please use a combination of double quotes and apostrophes ("'value'"). In cmd.exe you can just use double quotes ("value") but in powershell.exe you should use backticks ( `"value`") or apostrophes ('value'). Using the combination allows for both shells to work without issue, except for when the next section applies.
  • Pass quotes in arguments: When you need to pass quoted values to to something like a native installer, you are in for a world of fun. In cmd.exe you must pass it like this: -ia "/yo=""Spaces spaces""". In PowerShell.exe, you must pass it like this: -ia '/yo=""Spaces spaces""'. No other combination will work. In PowerShell.exe if you are on version v3+, you can try --% before -ia to just pass the args through as is, which means it should not require any special workarounds.

Upvotes: 24

Related Questions