Skip to content

Instantly share code, notes, and snippets.

@TheCakeIsNaOH
Created June 24, 2020 22:08
Show Gist options
  • Save TheCakeIsNaOH/d382fb7760fe7167ef45eee16731eaac to your computer and use it in GitHub Desktop.
Save TheCakeIsNaOH/d382fb7760fe7167ef45eee16731eaac to your computer and use it in GitHub Desktop.
Use a packages.config with the chocolatey global directory override.
param(
[parameter(Mandatory=$false, Position=1)][string]$installDir = 'C:\',
[parameter(Mandatory=$false, Position=0)][string]$pkgConfigPath = (Join-Path "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" 'install.config')
)
if (!(Test-Path $installDir)) {
Throw 'did not find override directory'
}
if (!(Test-Path $pkgConfigPath)) {
Throw 'did not find package config file'
}
[xml]$pkgConfig = Get-Content $pkgConfigPath
$pkgConfig.packages.package.id | ForEach-Object {
$overrideDir = (Join-Path $installDir $_)
#Write-Host $overrideDir
If (!(Test-Path $overrideDir)) {
$null = New-Item -ItemType Directory -Path $overrideDir
}
Start-Process -FilePath "choco" -ArgumentList "install $_ --install-directory=$overrideDir" -NoNewWindow -Wait
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment