Skip to content

Instantly share code, notes, and snippets.

@steviecoaster
Created November 23, 2022 20:33
Show Gist options
  • Save steviecoaster/ef0bafbb8fcf184bd75646239335eb65 to your computer and use it in GitHub Desktop.
Save steviecoaster/ef0bafbb8fcf184bd75646239335eb65 to your computer and use it in GitHub Desktop.
Package parameters example
$ErrorActionPreference = 'Stop'
$toolsDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
#Receive the package parameters from a package as a hashtable
#Example: choco install bob -y --package-parameters="'/Server=someserver /User=Bob /Enable'"
$pp = Get-PackageParameters
#You can then access the hashtable using any method you would normally use, both of the following will retrieve the value for the specified key.
$Server = $pp['Server'] #index of key
$User = $pp.User #key property
#Parameters with no input are treated like a Boolean. Passing it equates to $true, not passing it equates to false
$Enabled = $pp['Enable'] #This will evaluate to $true since '/Enable' was passed as a package parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment