Skip to content

Instantly share code, notes, and snippets.

@NiceRath
Created August 12, 2024 13:21
Show Gist options
  • Save NiceRath/9c93490b6f1003ef7d6204bfd7e71ff6 to your computer and use it in GitHub Desktop.
Save NiceRath/9c93490b6f1003ef7d6204bfd7e71ff6 to your computer and use it in GitHub Desktop.
Chocolatey - Install MSI Packages on Windows Startup
# NOTES:
# you need to install chocolatey first: https://community.chocolatey.org/install.ps1
# source for ChocolateyInstallPackage: https://github.com/chocolatey/choco/blob/master/src/chocolatey.resources/helpers/functions/Install-ChocolateyInstallPackage.ps1
# source for helper functions: https://github.com/chocolatey/choco/tree/master/src/chocolatey.resources/helpers/functions
# this script need to be copied to your client; it may not work if executed through a network share
# you also need to copy those helper-function (see HELPERS_INCLUDE below) to your clients (see HELPERS_PATH below)
$LOGFILE = 'C:\gpo\logs\choco.log'
$SCRIPT_PATH = 'C:\gpo\scripts\choco'
$HELPERS_PATH = "$SCRIPT_PATH\helpers"
$MSI_PATH = '\\<DOMAIN>.local\software\distribution\msi'
# MSI file name => msi install flags
$INSTALLERLIST = @{
'nxlog' = '/norestart /qn'
}
$HELPERS_INCLUDE = @(
'Install-ChocolateyInstallPackage'
'Write-FunctionCallLogMessage'
'Start-ChocolateyProcessAsAdmin'
'Get-OSArchitectureWidth'
'Test-ProcessAdminRights'
'Set-PowerShellExitCode'
) # dependencies => helper scripts
echo '####################' | Tee-Object -Append -Filepath $LOGFILE
Get-Date | Tee-Object -Append -FilePath $LOGFILE
echo 'Starting chocolatey software msi-deployment' | Tee-Object -Append -Filepath $LOGFILE
ForEach ($script in $HELPERS_INCLUDE) {
. ${HELPERS_PATH}/${script}.ps1 | Tee-Object -Append -Filepath $LOGFILE
}
ForEach ($app in $INSTALLERLIST.Keys) {
try {
$packageArgs = @{
fileType = 'msi'
file = "${MSI_PATH}\${app}.msi"
silentArgs = "$($INSTALLERLIST[$app])"
packageName = "$app"
validExitCodes= @(0,3010,1641)
}
Install-ChocolateyInstallPackage @packageArgs -ErrorAction SilentlyContinue | Tee-Object -Append -Filepath $LOGFILE
} catch {
echo "An error occurred while trying to install app '${app}'" | Tee-Object -Append -Filepath $LOGFILE
echo $_ | Tee-Object -Append -Filepath $LOGFILE
}
}
echo 'Finished chocolatey software msi-deployment' | Tee-Object -Append -Filepath $LOGFILE
Get-Date | Tee-Object -Append -FilePath $LOGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment