Screenshots & Flow
Show Toast 1
Run script.cmd (generated by PowerShell)
Show Toast 2
Code
# MrNetTek # eddiejackson.net/blog # 6/7/2020 # free for public use # free to claim as your own Clear-Host # TOAST MESSAGES # toast1 $toast1_heading = "Microsoft Intune Message" $toast1_msg1 = "Post Setup is about to begin." $toast1_msg2 = "`n`nLaunching app installs now...." # toast2 $toast2_heading = "Microsoft Intune Message" $toast2_msg1 = "Apps have been installed successfully!" # LOAD ASSEMBLIES [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [Reflection.Assembly]::LoadWithPartialName("System.Drawing") Add-Type -AssemblyName PresentationFramework # FOLDER LOGIC # Check if PowerShell folder does not exist if (!(Test-Path C:\PowerShell)) { # if not exist, create folder New-Item C:\PowerShell -ItemType directory -Force } # FUNCTION TO GENERATE THE TOAST ICON function Generate-Icon { # icon stored as base64 $Base64String = 'AAABAAEAGBgAAAAAIACICQAAFgAAACgAAAAYAAAAMAAAAAEAIAAAAAAAYAkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFBEOBRcTET1OPy99cVpHpHdhTbl8Zk/AdF9IuGtWQaNIOSt7KSEZLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwKCgMuJBZMhXJnzd65pP7juYz/68GW//HFnP/tw5n/5buR/9qwhP/VqX//t5Fu+zImHXEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGhINDlNBNJXNonT/5sOr/+nJuf/RqoH/17GM/922kf/atI7/0q6J/8mlf//BnHX/3bCF/3JYQtAA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rv9Jb47/CBghm19bVxEAAAAAmZmZSn19fZZ2dna2dHR0tF9fX4SPj48cAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARHB8SsNre4ZvR3/9+xdL/aKq6/1iYqP9Yma//TIeh/wAHDW0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZ32CNazT2cK88Pn/nNno/4DBzvJnpbLLRHJ9bwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACc2ej/nNno/43Q3/+N0N//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A//gBAP/gAAD/wAAA/8AAAMAAAACAAAAAgAAAAIAAAQCAAAMAgAAHAIAAHwDAAB8A4AAPAOAADwDgAA8A4AAPAOAADwDgAA8AwAAPAOAIHwDgD/8A8B//APw//wA=' # icon path and name $Image = 'c:\PowerShell\icon.ico' # convert base64 to bytes [byte[]]$Bytes = [convert]::FromBase64String($Base64String) # create icon from bytes [System.IO.File]::WriteAllBytes($Image,$Bytes) } # ICON LOGIC # Check if toast icon does not exist if (!(Test-Path C:\PowerShell\icon.ico)) { # if not exist, run icon function Generate-Icon } $global:icon = "c:\PowerShell\icon.ico" # CREATE YOUR SCRIPT Try { # make the script file New-Item "C:\PowerShell\script.cmd" -Type File -force # create content $Line1 = "start """" notepad.exe" $Line2 = "timeout /t 5" $Line3 = "taskkill /f /im notepad.exe" # output content to script $Line1 | Out-File -FilePath "C:\PowerShell\script.cmd" -Encoding ASCII $Line2 | Out-File -FilePath "C:\PowerShell\script.cmd" -Encoding ASCII -Append $Line3 | Out-File -FilePath "C:\PowerShell\script.cmd" -Encoding ASCII -Append } Catch { #Write-Host "Script Error Detected!" #[System.Windows.MessageBox]::Show('Script Error Detected!') } # TOAST 1 Try { # create the toast $global:toast1 = New-Object System.Windows.Forms.NotifyIcon $toast1.icon = $icon $toast1.text = "Downloading from cloud..." $toast1.visible = $true # show toast $toast1.ShowBalloonTip(10,$toast1_heading,$toast1_msg1 + $toast1_msg2,[System.Windows.Forms.ToolTipIcon]::Info) Start-Sleep -Seconds 10 # perform cleanup # note, you may want to move this cleanup to below the script, # so the icon notification will be available during the execution of the script $global:toast1.dispose() Remove-Variable -Name toast1 -Scope Global Start-Sleep -Seconds 5 } Catch { #Write-Host "Toast1 Error Detected!" #[System.Windows.MessageBox]::Show('Toast1 Error Detected!') } # EXECUTE SCRIPT Try { # execute the script you created (or just other cmdlets or commands) Start-Process -FilePath "C:\PowerShell\script.cmd" -WindowStyle Hidden -Wait } Catch { #Write-Host "Script Execution Error!" #[System.Windows.MessageBox]::Show('Script Execution Error!') } # TOAST 2 Try { # create the toast $global:toast2 = New-Object System.Windows.Forms.NotifyIcon $toast2.icon = $icon $toast2.text = "Great Success!" $toast2.visible = $true # show toast $toast2.ShowBalloonTip(10,$toast2_heading,$toast2_msg1,[System.Windows.Forms.ToolTipIcon]::Info) Start-Sleep -Seconds 10 # perform cleanup $global:toast2.dispose() Remove-Variable -Name toast2 -Scope Global Start-Sleep -Seconds 5 } Catch { #Write-Host "Toast2 Error Detected!" #[System.Windows.MessageBox]::Show('Toast2 Error Detected!') } # Note # HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify\ToastAppIdentities\ # Get-Member -InputObject $Global:toast1
Notes
Balloon Tip – Toast (older post demonstrating clickable events)
Disable Quiet Hours
Key: HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\QuietHours
Type: DWORD
Value: Enable
Data: 0
Enable Notifications
Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\PushNotifications
Type: DWORD
Value: ToastEnabled
Data: 1
Key: HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Explorer
Type: DWORD
Value: DisableNotificationCenter
Data: 0
Specific AppIDs you want enabled:
Key: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\TheAppID
Type: DWORD
Value: Enabled
Data: 1
Delete Key: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications /v DisableEnhancedNotifications
Create Icon Click Event
[void](Register-ObjectEvent -InputObject $toast1 -EventName MouseDoubleClick -SourceIdentifier IconClicked1 -Action { $global:toast1.dispose() Unregister-Event -SourceIdentifier IconClicked1 Remove-Job -Name IconClicked1 Remove-Variable -Name toast1 -Scope Global })
Using in Intune
Create
Create a Win32 PostSetup.intunewin app with the above code saved as PostSetup.ps1
Import
Import PostSetup.intunewin into Intune as a Win32 app
Install
ServiceUI.exe -process:explorer.exe %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File PostSetup.ps1
Uninstall
cmd /c
Custom Detection
Set up a file detection for C:\PowerShell\script.cmd
Screenshots
Import
Set Install and Uninstall
Set up detection rule
Review and Create