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

it will wait until the user presses ok or until the step timesout, you can adjust the timeout on the step

Share this post


Link to post
Share on other sites

the below script seems to be working, I will confirm after testing

$TSProgressUI = new-object -comobject Microsoft.SMS.TSProgressUI
$TSProgressUI.CloseProgressDialog()
#connect to Task Sequence environment
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
# read variables set in the task sequence
$title = $tsenv.Value("title")
$message = $tsenv.Value("message")
$returncode = $tsenv.Value("returncode")
$messagebox = new-object -comobject wscript.shell
write-output $messagebox.popup("$title ",100," $message ",0)
$returncode

thanks

Share this post


Link to post
Share on other sites

Niall,

I have modified the script to have an OK and a Cancel button to give the clients an option to do a Microsoft Office version upgrade.

How do i capture the response from the popup and use that response in the task sequence ?  ie: if they press OK, task sequence would continu and if they press cancel, task sequence stops and doesn`t perform the next steps(office upgrade).

Thanks

Share this post


Link to post
Share on other sites

i`ve got it to the point where the $returncode is good ...meaning if i run it manually, the value is 1 when i click Cancel and 0 when i click OK but how do i send that value back to the task sequence ?

Here is the lower part of the script:

 

 

# now show a popup message to the end user
write-host $title $message 
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
$box = [Windows.Forms.MessageBox]::Show(“$message”, “$title”, [Windows.Forms.MessageBoxButtons]::OKCancel, [Windows.Forms.MessageBoxIcon]::Information)
#$tsenv.Value("ReturnCode") = $ReturnCode

Switch ($box) {
   "OK" {
        Write-Host "OK"    
        $ReturnCode = "0"
        Exit 0
    }
    "Cancel" {
        Write-Host "Cancel"
        $ReturnCode = "1"
        Exit 1
        }
} 

 

Share this post


Link to post
Share on other sites

hi Kevin,

you could set a variable in the PowerShell script and use that to hold the value, something like this

$tsenv.Value('WhatValue') = $ReturnCode

then check for the value of that variable in your task sequence by checking for %WhatValue% (create an option on a step)

so it seems you are already doing something like that (but have it remmed out)

Share this post


Link to post
Share on other sites

Yes, i had it remmed out because i was testing without it but even without it being remmed out, it wasn`t working yesterday.

I do have a step in my TS that checks for a TS sequence variable of "returncode" and if it`s equal to 1, it runs the command --> cmd /c exit 1  and this command should make the TS fail (that`s what i want) but it doesnt fail and it continues on to the next step of upgrading software even though the user selected to cancel it for now.

 

Share this post


Link to post
Share on other sites

<![LOG[Expand a string: equals]LOG]!><time="14:23:44.440+180" date="06-07-2019" component="TSManager" context="" type="0" thread="9592" file="utility.cpp:790">
<![LOG[Expand a string: ReturnCode]LOG]!><time="14:23:44.440+180" date="06-07-2019" component="TSManager" context="" type="0" thread="9592" file="utility.cpp:790">
<![LOG[Expand a string: 1]LOG]!><time="14:23:44.440+180" date="06-07-2019" component="TSManager" context="" type="0" thread="9592" file="utility.cpp:790">
<![LOG[The action (Cancel = erreur) has been skipped because the condition is evaluated to be false]LOG]!><time="14:23:44.440+180" date="06-07-2019" component="TSManager" context="" type="1" thread="9592" file="instruction.cxx:696">
<![LOG[Not in SSL]LOG]!><time="14:23:44.483+180" date="06-07-2019" component="TSManager" context="" type="1" thread="9592" file="libsmsmessaging.cpp:10091">
<![LOG[Clear local default environment]LOG]!><time="14:23:44.509+180" date="06-07-2019" component="TSManager" context="" type="0" thread="9592" file="executionenv.cxx:809">
<![LOG[Execution of the instruction (Cancel = erreur) has been skipped]LOG]

 

you are only checking for ReturnCode=1 not zero from what I can see..

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.