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

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.

 

1TS.JPG

2TS.JPG

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

"OK" 
"OKCancel"
"AbortRetryIgnore"
"YesNoCancel"
"YesNo"
"RetryCancel"

$Type can be any of the following values

"Asterisk"
"Error"
"Exclamation"
"Hand"
"Information"
"None"
"Question"
"Stop"
"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]$OnTop="DefaultDesktopOnly",
    [string]$ReturnCode = 0
)

Function LogWrite
{
   Param ([string]$logstring)
   $a = Get-Date
   $logstring = $a,$logstring
   Try
{
    Add-content $Logfile -value $logstring  -ErrorAction silentlycontinue
}
Catch
{
    $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..."

[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[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

Hi,

Do i need to have MDT integrated into SCCM to do this? I really cannot seem to find out why when attempting to display the message box it fails. It appears to start running the script as a cmd line pops up, but then i get a generic error code from SMSTS logs. My goal is to update the BIOS on a computer if certain conditions are met. If the BIOS won't be updated, I wanted to have a message box so the user will know that it didn't fail and that they did not need the update so they wouldn't call the help desk claiming the TS did nothing. Otherwise the TS just claims a success. I could just inform the user "if it didn't do anything you didn't need it" in my email about the deployment you know how users are - no one reads all the email.

I can provide information needed to work through this, just let me know where we can start. 

Share this post


Link to post
Share on other sites

no you don't but you do need the serviceui,exe from mdt,

can you post your smsts.log so i can see what's going wrong ? and a view of your actual step in the task sequence

Share this post


Link to post
Share on other sites

Has anyone had luck with adding decision logic to this?  We only want the TS to proceed after the technician has clicked OK on the message.  It looks like the TS is continuing for us after getting the exit code, so the message only displays for a few minutes.

Thanks so much for what you've done for the SCCM community anyweb... these guides are great! 

Edited by Savvy_welwala

Share this post


Link to post
Share on other sites
Thanks so much for what you've done for the SCCM community anyweb... these guides are great!  

 

thanks !

 

can you please attach your smsts.log so i can take a look, it will explain why it's continuing for you (perhaps, continue on error is selected ?)

Share this post


Link to post
Share on other sites

Just wanted to follow up - the issue for us turned out to be an app installed during the TS forcing a reboot outside of TS process (which is why our SMSTS log wasnt really helpful).  Once we got that sorted out, works like a charm.  

  • Like 1

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...