Skip to content

Instantly share code, notes, and snippets.

@onyxhat
Last active July 15, 2016 15:24
Show Gist options
  • Save onyxhat/d69bde514e3fc68b693e71b738731be9 to your computer and use it in GitHub Desktop.
Save onyxhat/d69bde514e3fc68b693e71b738731be9 to your computer and use it in GitHub Desktop.
Stub for parsing Chocolatey --params string into variables in the chocolateyinstall.ps1/chocolateyuninstall.ps1
#$packageParameters = $env:chocolateyPackageParameters
$packageParameters = "var1 = val1;var2=`"val2 with spaces -`""
$match_pattern = "(?<key>(\w+))\s*=\s*(?<value>([`"'])?([\w- _\\:\.]+)([`"'])?)"
# Now parse the packageParameters using good old regular expression
if ($packageParameters -match $match_pattern ) {
$results = $packageParameters | Select-String $match_pattern -AllMatches
$results.matches | % {
Set-Variable -Name $_.Groups['key'].Value.Trim() -Value $_.Groups['value'].Value.Trim()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment