Improve your Windows as a Service process: Use Toast Notifications and Powershell App Deployment Toolkit to Upgrade Windows 10

Introduction

This is just a brief storytelling on, how you can add more user-friendliness and flexibility to your Windows as a Service process with Configuration Manager.

That be whether you fancy using Task Sequences or Feature Updates, this post will show you how you can wrap the process into an initial Toast Notification, which again sends the end-user into a PowerShell App Deployment Toolkit experience, which again will run either the Task Sequence or the Feature Update automatically.

Carrot on a stick: All the binaries used in these examples, are available for download throughout the post. That goes for PSADT as well as exported ConfigMgr applications.

Task Sequence

The process in details for Task Sequences will be like following steps:

  1. Toast Notification is displayed to the end-user
  2. End-user clicks Install Now
  3. Software Center is launched into the Installation status tab
  4. Application based on PSADT is being run automatically
  5. Going through the PSADT process will move Software Center into the OSD tab
  6. PSADT will launch the IPU Task Sequence automatically

Feature Update

The process in details for Feature Updates will be like following steps:

  1. Toast Notification is displayed to the end-user
  2. End-user clicks Upgrade Now
  3. Software Center is launched into the Installation status tab
  4. Application based on PSADT is being run automatically
  5. Going through the PSADT process will move Software Center into the Updates tab
  6. PSADT will launch the Feature Update automatically

PowerShell App Deployment Toolkit

I’m making both of the PSADT projects used respectively for Task Sequences: ToastNotificationDummy-TS.zip (5027 downloads ) and Feature Updates: ToastNotificationDummy-FU.zip (4718 downloads ) available for a direct download.

The only real interesting part of the content of either PSADT projects, is the PowerShell scripts, which are initiating the Task Sequence and the Feature Update.

I made a virtue of making proper commenting, so everything should hopefully make some sense. If not, let me know in the comments section.

Below script will run the Task Sequence with the corresponding package id, and write the detection method used in the application, into the registry:

# Package ID of the package or Task Sequence in Configuration Manager
$packageID = "KR100907"
# Load the Software Center Object
$softwareCenter = New-Object -ComObject "UIResource.UIResourceMgr"
# A simple test to see if the specified Package ID indeed is deployed to the device
$testPackageID = Get-CimInstance -Namespace root\ccm\clientsdk -Query "SELECT * FROM CCM_Program where PackageID = '$packageID'"
# If the package/task sequence is deployed to the device
if (-NOT[string]::IsNullOrEmpty($testPackageID)) {
    $programID = $testPackageID.ProgramID
    $registryPath = "HKCU:\SOFTWARE\imab.dk\WaaS\2004"
    # Create registry path for detection method if it does not exist
    if (-NOT(Test-Path -Path $registryPath)) { New-Item -Path $registryPath –Force }
    # Install the package/task sequence and launch the Software Center into the OSD tab. Write successful detection method to registry
    try {
        $softwareCenter.ExecuteProgram($programID,$packageID,$true)
        if (Test-Path -Path "$env:windir\CCM\ClientUX\SCClient.exe") { Start-Process -FilePath "$env:windir\CCM\ClientUX\SCClient.exe" -ArgumentList "SoftwareCenter:Page=OSD" -WindowStyle Maximized }
        New-ItemProperty -Path $registryPath -Name "PSADT-TS-DetectionMethod" -Value 0 -PropertyType "String" -Force
    }
    # Write failed detection method to registry and exit PSADT with error code 1
    catch {
        New-ItemProperty -Path $registryPath -Name "PSADT-TS-DetectionMethod" -Value 1 -PropertyType "String" -Force 
        exit 1   
    }
}
# Else exit PSADT with error code 1
else {
    exit 1
}

Below script will run the Feature Update with the corresponding Article ID, and write the detection method used in the application, into the registry:

# Article ID of the Software Update in Configuration Manager. Also referred to as the KB-article
$articleID = "3012973"
# Name of the update in Configuration Manager. This is not required, but might be needed if several updates are found within same Article ID
$updateName = ""
# A simple test to see if the update specified above indeed is deployed to the device
# Still using Get-WmiObject here, as I failed to successfully convert this into the Get-CmiInstance equivalent
$testUpdateID = Get-WmiObject -Namespace root\ccm\clientSDK -Query “SELECT * FROM CCM_SoftwareUpdate WHERE ArticleID = '$articleID' AND Name LIKE '%$updateName%'”
# If the update is deployed to the device
if (-NOT[string]::IsNullOrEmpty($testUpdateID)) {
    $RegistryPath = "HKCU:\SOFTWARE\imab.dk\WaaS\2004"
    # Create registry path for detection method if it does not exist
    if (-NOT(Test-Path -Path $RegistryPath)) { New-Item -Path $RegistryPath –Force }
    # Install the update and launch the Software Center into the updates tab. Write successful detection method to registry
    try {
        Invoke-WmiMethod -Namespace root\ccm\clientsdk -Class CCM_SoftwareUpdatesManager -Name InstallUpdates -ArgumentList (,$testUpdateID)
        if (Test-Path -Path "$env:windir\CCM\ClientUX\SCClient.exe") { Start-Process -FilePath "$env:windir\CCM\ClientUX\SCClient.exe" -ArgumentList "SoftwareCenter:Page=Updates" -WindowStyle Maximized }
        New-ItemProperty -Path $RegistryPath -Name "PSADT-FU-DetectionMethod" -Value 0 -PropertyType "String" -Force
    }
    # Write failed detection method to registry and exit PSADT with error code 1
    catch { 
        New-ItemProperty -Path $RegistryPath -Name "PSADT-FU-DetectionMethod" -Value 1 -PropertyType "String" -Force
        exit 1
    }
}
# Else exit PSADT with error code 1
else {
    exit 1
}

Toast Notification Script

The Toast Notification Script is obviously my script of the same name here: https://github.com/imabdk/Toast-Notification-Script

The script is run with a config.xml file, which is similar to the below illustration.

The important bits here are following:

  • UpgradeOS – This enables the toast notification to consider the build of Windows 10
  • TargetOS – This is the actual build of Windows 10 once the upgrade is complete. (I intentionally configured the build to 19042 for testing purposes. 19041 = 2004)
  • RunApplicationID – This is the Application ID of the application in ConfigMgr running the PSADT
  • Action – This is the custom protocol (HKCU\SOFTWARE\Classes\ToastRunApplicationID), referring to the custom script (C:\ProgramData\ToastNotificationScript\ToastRunApplicationID.ps1), running the Application ID via Software Center

NOTE: The Toast Notification Script is capable of running Feature Updates as well as Task Sequences directly from the Action button. Both of the examples used in this post, are leveraging the ability to run applications directly from the action button in order to take advantage of the PSADT capabilities.

ConfigMgr Applications

Yet again and for the sake of everyone, I’m making an export of both applications in Configuration Manager available for download.

Task Sequence: TOAST-PSADT-TS.zip (4948 downloads ) and Feature Update: TOAST-PSADT-FU.zip (4580 downloads )

These can be imported directly into your ConfigMgr environment, where the PSADT projects downloaded above, will be the source files – everything standard ConfigMgr.

Below is an example of one of the applications made available in the Software Center:

Again, if any questions, don’t hesitate to reach out in the comment section down below.

ENJOY 🙂

15 thoughts on “Improve your Windows as a Service process: Use Toast Notifications and Powershell App Deployment Toolkit to Upgrade Windows 10”

  1. Hello,
    Great Work!
    I don’t get how the PSTOOLKIT should work with your Toast notification script.
    I’ve downloaded your PSTOOLKIT (ToastNotificationDummy – TS); and edited the standard PSAPPTOOLKIT ps1…but where should your TOAST notification files be?
    In the same package of the pstoolkit?

    Reply
    • The toast notification is separate, and is the one launching the PSADT. The PSADT is there for you to download because of the custom powershell inside, which is able to launch a task sequence. So you got to fetch the toast notification separately 🙂

      Reply
  2. Sorry. the script part has not been pasted correctly.

    # Snooze button – this option will always enable both action button and dismiss button regardless of config settings
    if ($SnoozeButtonEnabled -eq “True”) {
    Write-Log -Message “Creating the xml for snooze button”
    [xml]$Toast = @”

    $AttributionText
    $HeaderText

    $TitleText

    $BodyText1

    $BodyText2

    $BodyText3

    $BodyText4

    “@
    }

    Reply
    • You cannot do that, as there’s a limit on how much content the toast notification can contain. If you add too much content, you will start seeing the toast render without buttons etc. 🙂

      Reply
  3. Hello there, is there a way to make the toast notification thing without giving access to the non admins to execute everything from the Software Center? If not, i’ll try to use PSADT as system to execute the IPU TS.

    Thanks for your answer, niiiice Toasts by the way.

    Reply
  4. When I try to run an application that isn’t an upgrade it cannot find the package ID “Write-log : PackageID: MH1001E6 was not found in the WMI as deployed to the client.” However, that package is deployed and sitting in software center. Does this not work on regular packages or just OS Upgrades and updates? Thanks.

    Reply
    • Should work with regular packages as well. I have tested that. Have you ticked ON on the program of the package, to allow users to run the program regardless of asssignments? Is the package available og required?

      Reply
      • It’s an application not a package, and is available, not required. Does it need to be a package? In order to install it successfully, should the package run as administrator and the toast as user?

        Reply
        • I see. If it’s an application, there’s a separate option for that, where the application ID needs to be configured in the config.xml. Looking at your log file, you have entered a package id and not an application id? 🙂

          Reply
    • If you enable the snooze button, the script is currently designed to always show all 3 buttons. If you don’t use snooze, you can customize the buttons as you want.

      Reply
  5. Hey and thanks for the great scripts.

    Im trying to get this to work with a Task Sequence but having trouble understanding one thing.

    So for the Deploy-Application.ps1

    should i add Toast-Notification-Script.ps1 -Config .\Run-PackageID.ps1

    to get it to work with the toast notifications? i cant really get it to work, get all kinds of errors 🙂

    Thanks,

    Johan

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.