Jump to content


anyweb

How can I display custom messages in a task sequence using PowerShell in System Center Configuration Manager (Current Branch)

Recommended Posts

Introduction

At the start of this series of step by step guides you installed System Center Configuration Manager (Current Branch), then you configured discovery methods. Next you configured boundaries to get an understanding of how automatic site assignment and content location works. After that you learned how to update ConfigMgr with new features and fixes using a new ability called Updates and Servicing and you learned how to configure ConfigMgr to use Updates and Servicing in one of these two modes:

To prepare your environment for Windows 10 servicing (this guide) you learned how to setup Software Updates using an automated method (via a PowerShell script) or manually using the ConfigMgr console. Next you used a PowerShell script to prepare some device collections, then you configured client settings for your enterprise and finally you'll deployed the ConfigMgr client agent using the software updates method which is the least intensive method of deploying the Configuration Manager client agent.

 

As System Center Configuration Manager (current branch) is being delivered as a service now, version 1602 was made available (March 11th, 2016) and you used Updates and Servicing to do an in-place upgrade to that version as explained here. Next you learned about how to use the Upgrade task sequence to upgrade your Windows 7, Windows 8 (and 8.1) and even your Windows 10 devices to a later build of Windows 10.

 

You then learned about the new Windows 10 servicing features which use Servicing Plans in ConfigMgr (Current Branch). Next you integrated MDT 2013 update 2. MDT integration with ConfigMgr is useful as it provides additional functionality for operating system deployment scenarios such as Offline Language Package installation or User Driven Integration (UDI).

 

Next you learned how to deploy Language Packs offline for Windows 10. To assist with Windows 10 servicing and for applying appropriate software updates to your Windows 10 devices, you used PowerShell to add queries to the various Windows 10 collections.

 

Next you took a deeper look at the Windows 10 Upgrade task sequence, and learned one way of dealing with potential upgrade issues. While that method will flag a problem, such as determining the system UI language doesn't match the provided media, it won't allow you to continue with the upgrade. Next you learned how to upgrade the operating system when a language pack was installed, provided that the system UI language is from a 'list' of approved languages that you intend to support.

 

This guide will show you how to display customized messages to a user during a task sequence, and how to set an exit code which could allow you to deliberately fail an action if necessary. All that's required is a few steps to set variables, a PowerShell script, and the serviceUI.exe executable from MDT 2013 Update 2.

 

Step 1. Create a package

On your ConfigMgr server, in the sources share, create a folder called Display Custom Message and place the DisplayCustomMessage.ps1 PowerShell script available in the downloads section of this guide, in the folder. Even though you might be deploying an X64 operating system, locate, select and copy the x86 architecture version of ServiceUI.exe from the Sources\OSD\MDT\MDT2013u2\Toolkit\Tools\x86 folder

 

serviceui.png

 

into the Display Custom Message folder as shown below.

 

display custom message.png

 

In the ConfigMgr console, Software Library, select Packages and right click, choose Create Package. Fill in the following details,

 

create package.png

 

Choose Do not create a program and then continue through the wizard until completion.

 

package created.png

 

Once the package is created, right click the package and choose Distribute Content.

 

distribute content.png

 

Distribute the package to your distribution points.

 

distributed.png

 

 

Step 2. Create a custom task sequence

In the ConfigMgr console, in Software Library, select Operating Systems and right click on Task Sequences, choose Create Task Sequence.

 

Create Task Sequence.png

 

select Create a new custom task sequence

 

create a new custom task sequence.png

 

give the task sequence a suitable name such as Display Custom Messages with exit codes

 

create task sequence wizard.png

 

continue through that wizard until completion.

 

custom ts done.png

 

Step 3. Edit the task sequence

Right click on the newly created task sequence and choose edit

 

edit task sequence.png

 

It will appear blank, click on the Add Drop down and add a New Group called Display Custom Message

 

Create a new Set Task Sequence Variable step called Set Title with a Task Sequence Variable called Title, with a suitable value as follows:

 

set title.png

 

Create a new Set Task Sequence Variable step called Set Message with a Task Sequence Variable called Message, with a suitable value as follows:

 

set message.png

 

Create a new Set Task Sequence Variable step called Set ReturnCode with a Task Sequence Variable called ReturnCode, with a suitable positive value as follows:

 

set returncode.png

 

Click Add and choose Run Command Line, name the step Display Custom Message and paste in the following based on what operating system the client is using:

 

For Windows 8

ServiceUI.exe -process:TSProgressUI.exe %windir%\sysnative\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy bypass -nologo -file DisplayCustomMessage.ps1

For Windows 10

ServiceUI.exe -process:TSProgressUI.exe %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden -NoProfile -ExecutionPolicy bypass -File DisplayCustomMessage.ps1

 

For Package, select the Display Custom Message package created above. (screenshot below if for Windows 8 os)

 

display custom message step.png

 

Copy the entire group and paste it below the first group

 

copy paste.png

 

Edit the Set Message step as below

 

set message to fail.png

 

Edit the Set ReturnCode step, and choose a value that the Options tab on the Display Custom Message step is not going to expect such as 1, this will cause the next step to fail when it returns the return code.

 

returncode 1.png

 

Apply your changes and exit the Task Sequence wizard.

 

ready to apply.png

 

Step 4. Deploy the task sequence

Right Click on the task sequence and choose Deploy

 

deploy task sequence.png

 

Choose a suitable collection and use a purpose of Available.

 

deployed.png

 

Step 5. Review the capabilities

On a client computer that is in the collection that the task sequence was deployed to, open Software Center and select the Display Custom Message with exit codes task sequence.

 

display custom message in software center.png

 

choose Install

 

install.png

 

and after a few moments the first popup message appears !

 

custom message.png

 

As the ReturnCode for the first message was set to a value we expected (0 or 3010) it did not fail the task sequence. Click OK to continue...

 

the next message appears, note the different text, and it's hinting towards what will happen

 

custom message 2.png

 

Clicking OK will produce the failure

 

task sequence failed.png

 

Which is OK because we were expecting it, in fact, the ReturnCode we set (1) is listed in the failure message. In a real Production task sequence however, you'd take care of failures and deal with them in a professional way, I just want you to see that we can actually set the ReturnCode via the custom message.

 

To get more proof of that refer to the SMSTS.log file, and you can see that it's setting the ReturnCode to the value we chose

 

exit code 1.png

 

result !

 

Summary

Popping up messages to users during a task sequence is sometimes necessary, and when things go wrong, you sometimes need to fail the task sequence or set a ReturnCode to do a planned action. This guide helps you do both of those things dynamically.

 

Related Reading

Downloads

 

  • Thanks 1

Share this post


Link to post
Share on other sites

very nice help.

at the moment I have the problem that I want to give the powershell script parameters.

Do you know the right way?

 

thats my test (tried with ' and "):

ServiceUI.exe -process:Explorer.exe %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy RemoteSigned -File ".\script.ps1" -Message 'Hello,' -Title 'Test'

 

When I run it on the local system in the powershell with this everything is nice:

.\powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy RemoteSigned -File ".\script.ps1" -Message 'Hello,' -Title 'Test'

 

 

When I write the parameters in the script itself everything is ok with this:

ServiceUI.exe -process:Explorer.exe %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy RemoteSigned -File ".\script.ps1"

 

 

So now I dont know how to write it correctly in the SCCM (maybe wrong use of " ' ) ...on the local computer everything works fine

Edited by windowsnap123

Share this post


Link to post
Share on other sites

7 hours ago, mlarkin said:

The download link for the powershell script doesn't work.

Can you post it again or somewhere else?

works fine for me, what happens when you click on it ?

Share this post


Link to post
Share on other sites

On 7/14/2017 at 11:29 AM, MichaelDK said:

Is it possible to show the message and continue the task sequence (no wait for click or timeout)

yes but you'd have to edit the powershell script and change the function that displays the message box, the link below has a function to generate what you want

https://stackoverflow.com/questions/32827376/how-to-create-a-popup-message-in-powershell-without-buttons

Share this post


Link to post
Share on other sites

Thanks for this solution. Very nice. The best part is not having to change the script to create a different message! Has been great for win10 upgrades to notify users of low disk space and vpn connection.

Question - I'm trying to use this in Winpe 64bit v14393 for standalone media expired/outdated notification. It's giving me the error "This version of serviceui.exe is not compatible with the version of Windows you're running..". Have you tried to use this in winpe? Any suggestion on how to get passed this? I am not using the "disable 64bit file system redirection" option in the task.

Thanks!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.