Jump to content


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

Recommended Posts

Yes, that`s my issue.  The Cancel = error step in the TS is checking to see if the return code is "1" in order to run.  This would mean that the user clicked the "cancel" button in order to deffer the software install.  If the return code is 1, the TS will run "cmd /c exit 1" which will cause the TS to fail.

My problem is that even if the user clicks "OK" or "Cancel", the return code is always 0...….or maybe it`s the script that is not assigning the ReturnCode value.  I`ve never done anything like this so i`m just trying to piece things together to make it work but no luck so far.




Share this post

Link to post
Share on other sites

hmm maybe use bits out of my DisplayMessageInIntune.ps1 script shown below


# niall brady 2018/1/26
# simple script to display a popup message in Microsoft Intune
# Customize the message by editing the variables

$Option can be any of the following values


$Type can be any of the following values

"Warning "

$WhichButtonHasFocus indicates the default button (that initially has focus). This is required if the DefaultDesktopOnly parameter is used.

DefaultDesktopOny forces the message box on top.

param (
    [string]$title = "www.windows-noob.com (c) 2018",     
    [string]$Message = "This is a popup message in Microsoft Intune !",
    [string]$Option = "OK",
    [string]$Type = "Information",
    [string]$WhichButtonHasFocus = "Button1",
    [string]$ReturnCode = 0

Function LogWrite
   Param ([string]$logstring)
   $a = Get-Date
   $logstring = $a,$logstring
    Add-content $Logfile -value $logstring  -ErrorAction silentlycontinue
    $logstring="Invalid data encountered"
    Add-content $Logfile -value $logstring
   write-host $logstring
# script starts here
$Logfile = "C:\Windows\temp\DisplayMessageInIntune.log"
LogWrite "Starting DisplayMessageInIntune script..."

[Windows.Forms.MessageBox]::Show(“$message”, “$title”, [Windows.Forms.MessageBoxButtons]::$Option, [Windows.Forms.MessageBoxIcon]::$Type,$WhichButtonHasFocus,$OnTop)
#[Windows.Forms.MessageBox]::Show(“$message”, “$title”, [Windows.Forms.MessageBoxButtons]::$Option, [Windows.Forms.MessageBoxIcon]::$Type,$WhichButtonHasFocus)
LogWrite "Ending DisplayMessageInIntune script... with returncode $ReturnCode"
Exit $ReturnCode

or going back to your edits, i notice you have a 'write host' to display the value do you ever see that ? i doubt it, therefore i'd add logging, you can use the LogWrite function I have in my Intune powershell script as it logs everything and then modify it to capture the results of the click (and value)

ok ?


Share this post

Link to post
Share on other sites

ah !  Thank you so much !!

i`ve now made changes to my .ps1 so that it will either have succes or failure….instead of having the TS run a task in relation to the returncode of the script adding this code at the end of my script….and it works !

So now when a user clicks "cancel", the script fails, therefore the TS fails also….and thats what i want. 

If the user clicks "OK", the scripts is succesful and the TS continues.

LogWrite "Ending DisplayMessage script... with returncode $ReturnCode"

if ($ReturnCode = OK)
{exit 0}
elseif ($ReturnCode = Cancel)
{exit 1}
else {
logWrite("script did not exit with 0, 1 or cancel")


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.

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.


  • Create New...