This week is focused on the end-user experience. More specifically, the end-user experience for scripted actions. Especially when deploying apps, or performing other scripted actions, by using the PowerShell functionality, there could be actions of interest for the end-user.In that case I would like to notify the end-user. The app deployment functionality already provides the option to display notifications to the end-user and in this post I’ll show a simple, but effective method, to also display notifications to scripted installations. That can be a nice addition to this post about combining the powers of the Intune Management Extension and Chocolatey. In this post I’ll provide an updated script, followed by the required configuration steps. I’ll end this post with the end-user experience.
Script
The first step is to create a PowerShell script that can be used to install Chocolaty packages and to show notifications to the end-user after a successful installation. The following script provides the exact mentioned functionality, nothing more, nothing less, and the script is documented to provide some more details about the exact actions. The script uses the BurntToast module, which is available in the PowerShell Gallery, to display notifications.
<# | |
.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 | |
https://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" | |
} | |
} |
Note: The BurntToast module, which is used, will only work for the logged-on user. For functionality in SYSTEM context, additional adjustments are required.
Configuration
The next step is to configure the PowerShell script in Microsoft Intune. The script must run in SYSTEM context to easily install new Windows Features. To upload the script, follow the five steps below. After uploading the script, simply assign the script to the required devices. I deliberately mentioned devices, as I’m using a security group that filters on the version of Windows 10. The good thing is that nowadays these scripts can be assigned to devices and that users are not required to be logged on first.
1 | Open the Azure portal and navigate to Intune > Device configuration > PowerShell scripts to open the Device configuration – PowerShell scripts blade; |
2 | On the Device configuration – PowerShell scripts blade, click Add to open the Script Settings blade; |
3a | ![]()
Note: The script must be less than 200 KB. |
3b | ![]()
Explanation: This configuration will make sure that the script will run by using the user credentials on 32-bit and 64-bit devices. |
Note: Keep in mind that the script will be running by using the user credentials, which will require the user to be local administrator for installing the different apps.
End-user experience
Let’s end this post by having a look at the end-user experience. This time I choose to go for an animated gif, as that will provide the best example of the end-user experience. Below is an example of the script installing 7-Zip and Notepad++.
More information
For more information about the BurtToast module, please refer to the PowerShell Gallery.
New-BurntToastNotification -Text “Thanks for sharing!”, Cool find sir.”
🙂
Thank you, Rkast!
What is C:\Temp\DefaultBG.jpg. Where is it defined?
Hi Mark,
Sorry, I forget to mention that in the article and I forgot to make a variable of that in the example script. That’s just a custom image that I used for displaying the picture in the notification. You can basically use any picture at there, as long as it’s available for the device.
Regards, Peter