Created
April 17, 2019 19:04
-
-
Save pvanderwoude/8321c4ce9e286df841215bff087043ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Install Chocolatey packages. | |
.DESCRIPTION | |
This script will install Chocolatey packages and provide notifications to the user after succesful installation. | |
.NOTES | |
Author: Peter van der Woude | |
Contact: pvanderwoude@hotmail.com | |
Date published: 17-04-2019 | |
Current version: 1.0 | |
.LINK | |
http://www.petervanderwoude.nl | |
.EXAMPLE | |
Install-ChocoApps.ps1 | |
#> | |
#Variable that contains the Chocolatey packages that should be installed | |
$ChocoPackages = @("notepadplusplus.install","7zip.install") | |
#Variable that contains the default installation directory of Chocolatey | |
$ChocoInstall = Join-Path ([System.Environment]::GetFolderPath("CommonApplicationData")) "Chocolatey\bin\choco.exe" | |
#Verify if BurntToast is installed | |
if (!(Get-Module -Name BurntToast -ListAvailable)) { | |
try { | |
#Install Nuget package provider (prevent notifications when installing modules) | |
Install-PackageProvider Nuget -Force -ErrorAction Stop | |
#Install BurntToast | |
Install-Module BurntToast -Force -ErrorAction Stop | |
} | |
catch { | |
Throw "Failed to install BurntToast module" | |
} | |
} | |
#Verify if Chocolatey is installed | |
if(!(Test-Path $ChocoInstall)) { | |
try { | |
#Install Chocolatey | |
Invoke-Expression ((New-Object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Stop | |
} | |
catch { | |
Throw "Failed to install Chocolatey" | |
} | |
} | |
#Run through the required Chocolatey packages | |
foreach($Package in $ChocoPackages) { | |
try { | |
#Install Chocolatey package | |
Invoke-Expression "cmd.exe /c $ChocoInstall Install $Package -y --force --ignorechecksum" -ErrorAction Stop | |
#Display toast notification (not critical, no specific catch) | |
New-BurntToastNotification -AppLogo "C:\Temp\DefaultBG.jpg" -Text "Intune application deployment","Succesfully installed $Package!" -ErrorAction SilentlyContinue | |
} | |
catch { | |
Throw "Failed to install $Package" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment