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

Ups,

I just noticed my cmd line is wrong. Changing "-ExecutionPolic y bypass" to "-ExecutionPolicy bypass" fixed it. Now message box pops up but there is no title and message. :(  

myemptybox.PNG.005e84535d6d78f4e4698facb3a16ef3.PNG

Share this post


Link to post
Share on other sites


did you modify my powershell script in any way ? if not, can you show the set * variable steps ?

Share this post


Link to post
Share on other sites

Actually I didn't change anything at first but somehow I was not able to make it worked. Because msgbox coming empty, I thought it could not get the title, message values from TS. Then I decided to change the PS file and enter the custom message, title in the ps file, instead of fetching from TS. It works now. Here is the PS file I am using. Thanks. 

 

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Windows.Forms.MessageBox]::Show("This is the first line of your msg. `nThis is the second line of the msg", "This is the Title of Msg Box", [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Warning)

Exit 0 

Share this post


Link to post
Share on other sites
On 10/22/2018 at 3:24 PM, selimatmaca said:

Ups,

I just noticed my cmd line is wrong. Changing "-ExecutionPolic y bypass" to "-ExecutionPolicy bypass" fixed it. Now message box pops up but there is no title and message. :(  

myemptybox.PNG.005e84535d6d78f4e4698facb3a16ef3.PNG

Strange i have the same blank pop up too after i have moved over from sccm 2007 to current branch.

Share this post


Link to post
Share on other sites

hi i just tried it, and it works fine, you must be a member in order to download it, so did you try downloading it before becoming a member ? if so, now that you are a member simply re-try the download and you'll see it will work.

Share this post


Link to post
Share on other sites

and where do you see that error exactly ? can you show me a screenshot..

Share this post


Link to post
Share on other sites

How about this? No need for packages, or ServiceUI.

Run as a command line:

powershell.exe -command (new-object -ComObject Microsoft.SMS.TsProgressUI).CloseProgressDialog() ; (new-object -ComObject wscript.shell).Popup('Message Goes Here.',0,'Title Bar Text',0x0 + 0x30) ; Exit 0
 

Share this post


Link to post
Share on other sites

Can you re-upload the displaycustommessage.ps1 ? Its not available.

I have another question i hope you will help me with.

I created a messagebox with ok/cancel like this:

$box = [System.Windows.Forms.MessageBox]::show("Strømforsyningen er ikke tilsluttet.`n `n1.Tilslut strømforsyningen og tryk på OK for at forsætte.`n2.Tryk på Cancel for at annullere installationen.`n `nMed venlig hilsen`nFMI KAKI","Advarsel",1,48)

Switch ($box) {
    "OK" {
        Write-Host "Du trykkede OK"    
        Exit 0
    }
    "Cancel" {
        Write-Host "Du trykkede Cancel"
        Exit 99
    }
}

When i run it in Windows it works perfectly, the same when i try in Winpe manually. But when i put it in Task Sequence, the messagebox never appear and exit with 0 every time in Winpe, where I need to use it.

 

Share this post


Link to post
Share on other sites

hi

the powershell script is there, you just need to be logged in as a member to download it, so please try again.

the reason your popup doesn't appear is because it's running as system context, so you never see it (but SYSTEM does...), that's why we use ServiceUI.exe to get around that problem

Share this post


Link to post
Share on other sites

Great post, 

I am using this in my TS on it worked good all time.

But is there any way we can show message for x amount of time and after that time TS continues?

Any suggestions?

Regards

Anche

Share this post


Link to post
Share on other sites

good point... so can you fill me in with why you want to do this, give me a scenario...

Share this post


Link to post
Share on other sites
48 minutes ago, anyweb said:

good point... so can you fill me in with why you want to do this, give me a scenario...

May be i am wrong, I am deploying couple applications in custom TS. When the user run from software center it pops up message to close some applications. but what happens if I deploy it as required, does to run and popup message and wait to press ok or it continues?

 

Share this post


Link to post
Share on other sites

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

Thanks, how can I adjust the timeout. When I select the timeout(display custom message step) its throwing error

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

can you attach your smsts.log so i can see that step being executed please ?

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