Jump to content

Powershell popup not displaying

Recommended Posts

Hi all.

Im having a little trouble getting a scrip to work.

I have tried a few different options to get it all working, however nothing comes up.
so far i have tried.
condensing the script and just calling it in a script.
creating a script file and dumping it on the client machine and then calling it.

the script work pefectly if i just run it on the computer, but the second automate is involved. nothing.


the script is below for anyone interested


-windowstyle hidden
Add-Type -AssemblyName PresentationCore,PresentationFramework
$ButtonType = [System.Windows.MessageBoxButton]::Ok
$MessageIcon = [System.Windows.MessageBoxImage]::Exclamation
$MessageBody = "This computer will reboot overnight. 
if you have any questions or concerns call "
$MessageTitle = "Computer will reboot"
$Result = [System.Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)

Share this post

Link to post
Share on other sites

Which script function in Automate are you using to call the powershell code? It is likely the script is running as the "SYSTEM" user and not the currently logged in console user. When running as SYSTEM, popups won't be displayed on the Desktop. 

Gavsto has a nice write up on how to run scripts in the context of the currently logged on user. Running Scripts as Logged In User

Share this post

Link to post
Share on other sites

Methods i have tried so far.


Powershell command as Admin/Powershell command(bothways)
Add-Type -AssemblyName PresentationCore,PresentationFramework; $ButtonType = [System.Windows.MessageBoxButton]::Ok; $MessageIcon = [System.Windows.MessageBoxImage]::Exclamation; $MessageBody = "This computer will reboot overnight. if you have any questions or concerns call ***********";$MessageTitle = "Computer will reboot";$Result = [System.Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
This returns as successful but nothing happens


script saved to our automate server saved to temp folder on customers computer.
powershell.exe -File %windir%\Temp\Computerwillreboot.ps1
This returns as successful, the file is on the computer at the required location but it does not trigger.
if i use command prompt on the computer putting the second part. it work. if i use the labtech cmd interface it returns "ok" but nothing happens.


I know this is possible but

I do not know de wey


Share this post

Link to post
Share on other sites

@ATrotterYou just need to run your command from `console shell` on the proper console number so the popup displays on their desktop. If you just run default Automate commands it's going to send that popup to the `system` desktop....so obviously the user will never see it. The key here is %consolenumber%, which will be the console number of the logged in user. %consolenumber% will not have a value until you GET the value though, so here is what you need to do...

  1. Use the script function "IF Console Logged On". Leave the username blank, then tell it what label to go to if a user IS logged in like :loggedOn
  2. After your :loggedOn label, insert another line and use the script function "Console Shell", put your command in the command text box, then fill out the Console Number box with %consolenumber% (which now = the console number of the user detected to be logged in from step 1)

That's it! I use powershell popups quite a bit like this. 

  • Like 1

Share this post

Link to post
Share on other sites
On 9/24/2019 at 11:45 AM, Christopher Gent said:

What if you want to use a function within the powershell command?


Figured this out, if you want to call on a script with a function through command line you need to preload the assemblies at the top of the script.  

Edited by Christopher Gent

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