Get-PackageParameters

Get-PackageParameters

Get-PackageParameters

Parses a string and returns a hash table array of those values for use in package scripts.

Syntax

Get-PackageParameters `
  [-Parameters <String>] `
  [-IgnoredArguments <Object[]>] [<CommonParameters>]

Description

This looks at a string value and parses it into a hash table array for use in package scripts. By default this will look at $env:ChocolateyPackageParameters (--params="'/ITEM:value'") and $env:ChocolateyPackageParametersSensitive (--package-parameters-sensitive="'/PASSWORD:value'" in commercial editions).

Learn more

Notes

If you need compatibility with older versions of Chocolatey, take a dependency on the chocolatey-core.extension package which also provides this functionality. If you are pushing to the community package repository (https://community.chocolatey.org/packages), you are required to take a dependency on the core extension until January 2018. How to do this is explained in the docs.

The differences between this and the chocolatey-core.extension package functionality is that the extension function can only do one string at a time and it only looks at $env:ChocolateyPackageParameters by default. It also only supports splitting by :, with this function you can either split by : or =. For compatibility with the core extension, build all docs with /Item:Value.

Aliases

Get-PackageParametersBuiltIn

Examples

EXAMPLE 1


# The default way of calling, uses `$env:ChocolateyPackageParameters`
# and `$env:ChocolateyPackageParametersSensitive` - this is typically
# how things are passed in from choco.exe
$pp = Get-PackageParameters

EXAMPLE 2


# see https://docs.chocolatey.org/en-us/guides/create/parse-packageparameters-argument
# command line call: `choco install <pkg_id> --params "'/LICENSE:value'"`
$pp = Get-PackageParameters
# Read-Host, PromptForChoice, etc are not blocking calls with Chocolatey.
# Chocolatey has a custom PowerShell host that will time these calls
# after 30 seconds, allowing headless operation to continue but offer
# prompts to users to ask questions during installation.
if (!$pp['LICENSE']) { $pp['LICENSE'] = Read-Host 'License key?' }
# set a default if not passed
if (!$pp['LICENSE']) { $pp['LICENSE'] = '1234' }

EXAMPLE 3


$pp = Get-PackageParameters
if (!$pp['UserName']) { $pp['UserName'] = "$env:UserName" }
if (!$pp['Password']) { $pp['Password'] = Read-Host "Enter password for $($pp['UserName']):" -AsSecureString}
# fail the install/upgrade if not value is not determined
if (!$pp['Password']) { throw "Package needs Password to install, that must be provided in params or in prompt." }

EXAMPLE 4


# Pass in your own values
Get-PackageParameters -Parameters "/Shortcut /InstallDir:'c:\program files\xyz' /NoStartup" | set r
if ($r.Shortcut) {... }
Write-Host $r.InstallDir

Inputs

None

Outputs

  • [HashTable]

Parameters

-Parameters [<String>]

OPTIONAL - Specify a string to parse. If not set, will use $env:ChocolateyPackageParameters and $env:ChocolateyPackageParametersSensitive to parse values from.

Parameters should be passed as "/NAME:value" or "/NAME=value". For compatibility with chocolatey-core.extension, use :.

For example `-Parameters "/ITEM1:value /ITEM2:value with spaces"

Property Value
Aliases params
Required? false
Position? 1
Default Value
Accept Pipeline Input? false

-IgnoredArguments [<Object[]>]

Allows splatting with arguments that do not apply and future expansion. Do not use directly.

Property Value
Aliases
Required? false
Position? named
Default Value
Accept Pipeline Input? false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters http://go.microsoft.com/fwlink/p/?LinkID=113216 .

Function Reference

:choco-info: NOTE

This documentation has been automatically generated from Import-Module "$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1" -Force; Get-Help Get-PackageParameters -Full.

View the source for Get-PackageParameters