cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

PowerShell Script to send a msgBox to the User Logged in currently (not working)

tsmith
Novitiate II

I'm currently in the process of developing a simple script to delete caches and cookies, but I want a msgbox to appear to the user currently signed into the desktop. I have tested this part of the script locally and it works perfectly fine.

The Script:

#Testing Msg box alone#
Add-Type -AssemblyName PresentationFramework
$ButtonType = [System.Windows.MessageBoxButton]::Ok
$MesssageIcon = [System.Windows.MessageBoxImage]::Warning
$MessageBody = "Please save anything open in your current Web Browser, this includes Google Chrome, Microsoft Edge, and Mozilla FireFox and close each one respectively.
We will be deleting your cache and cookies. 

-IT"
$MessageTitle = "Read Me"
$Result = [System.Windows.MessageBox]::Show($MessageBody, $MessageTitle,$ButtonType,$MesssageIcon)

When I try to add the Script to Jump Cloud commands itself and run it, it'll error out with a Function timeout error of 124.

I even tried using the file download feature of Jump Cloud, where you can download a file before the command is run in C:\Windows\Temp. Then having the command, itself point to that location and run the script. Unfortunately, this still provides a Function error of 124.

I guess I'm confused as to why I can get it to work locally but not via JC Remote command.

Any advice would be greatly appreciated.

1 ACCEPTED SOLUTION

simonbh-cbu
Novitiate II

 

Have you tried running this using the RunAsUser module?

 

# If PSModule RunAsUser is not installed, install it
if ( -not (get-installedModule "RunAsUser" -ErrorAction SilentlyContinue)) {
install-module RunAsUser -force
}

$Command = {

#Testing Msg box alone#
Add-Type -AssemblyName PresentationFramework
$ButtonType = [System.Windows.MessageBoxButton]::Ok
$MesssageIcon = [System.Windows.MessageBoxImage]::Warning
$MessageBody = "Please save anything open in your current Web Browser, this includes Google Chrome, Microsoft Edge, and Mozilla FireFox and close each one respectively.
We will be deleting your cache and cookies. 

-IT"
$MessageTitle = "Read Me"
$Result = [System.Windows.MessageBox]::Show($MessageBody, $MessageTitle,$ButtonType,$MesssageIcon)

}

invoke-ascurrentuser -scriptblock $Command

 

View solution in original post

2 REPLIES 2

simonbh-cbu
Novitiate II

 

Have you tried running this using the RunAsUser module?

 

# If PSModule RunAsUser is not installed, install it
if ( -not (get-installedModule "RunAsUser" -ErrorAction SilentlyContinue)) {
install-module RunAsUser -force
}

$Command = {

#Testing Msg box alone#
Add-Type -AssemblyName PresentationFramework
$ButtonType = [System.Windows.MessageBoxButton]::Ok
$MesssageIcon = [System.Windows.MessageBoxImage]::Warning
$MessageBody = "Please save anything open in your current Web Browser, this includes Google Chrome, Microsoft Edge, and Mozilla FireFox and close each one respectively.
We will be deleting your cache and cookies. 

-IT"
$MessageTitle = "Read Me"
$Result = [System.Windows.MessageBox]::Show($MessageBody, $MessageTitle,$ButtonType,$MesssageIcon)

}

invoke-ascurrentuser -scriptblock $Command

 

I have not used the RunAsUser Module, and just researched it after you sent this in.  

The code you added onto it made it work!

Thank you so much for your help!