Comments (16)
I did some preliminary testing and it seems:
Invoke-Command -ComputerName RemotePC -Credential Joe -ScriptBlock {Toast -Text 'Test'}
changed to simply:
Invoke-Command -ComputerName $env:COMPUTERNAME -ScriptBlock {Toast -Text 'Test'}
works.
I first verified by opening up a Command Prompt as SYSTEM. (PsExec.exe -i -s cmd.exe) and used the Invoke-Command above - toast messages appeared to me logged in (obviously not as SYSTEM).
Not completely trusting that, I made a quick scheduled task to run and test:
schtasks /create /TN ToastTest /RU SYSTEM /RL HIGHEST /TR "powershell.exe Invoke-Command -ComputerName $env:COMPUTERNAME -ScriptBlock {Toast -Text 'ToastTest'}" /SC ONCE /ST 20:33 /V1 /Z
..and the toast appeared!
I'm going to implement and test this methodology in my actual scripts (need to do some adjusting to local variables) and will report back.
Joy!
from burnttoast.
One possible solution: configure a second scheduled task that launches the toast under the logged in user context, then have your System task trigger the notification task.
from burnttoast.
Basically how I have it setup now...just messy for documentation/support for others on my team trying to indicate what parts of the process are setup/triggered in what way.
from burnttoast.
@nmcspadden No, I haven't revisited it yet.
My test above worked but ran into problems when trying to use a button with it. I couldn't get a $button=New-BTButton -Content "blahblah" to work sending it that way to SYSTEM. It would gave an error. I think I just didn't pass the variable correctly. I put it on hold because trying to debug it was driving me nuts. (It was probably the wee hours of the morning).
I plan to split it in two phases now 1> make it work from SYSTEM minus the button which should be super easy as proof of concept has occurred and will revisit very soon. 2> Figure out my error in passing the button variable around. (Hmmmm..... might "cheat" and just assign it as global then remove it. That way I don't have to "pass" it. Hmmmmm) Now I might have to revisit it today!
from burnttoast.
Actually I still failed previously as none of my variables would pass along. I'd get a toast message across to the logged in user (me!) from the SYSTEM account, but the message would not include the variable info I tried to pass along.
I searched and I searched and found a few Q&As about using Invoke-Command and passing variables. The suggested -ArgumentList (,$arrayname) and using $args[x] failed me as I'd get all the arguments instead of just the one element I wanted. The examples I tried worked, but when I tried them myself... no workie. Finally found one that suggestion using and defining with param().
SUCCESS!
So the short of it for anyone who wants to send toast messages from the system account or other to all users, you can use this example:
(The following was tested by running PsExec.exe -i -s cmd.exe to get a Command Prompt as SYSTEM and then I ran PowerShell.)
So my little pet project of https://chocolatey.org/packages/chocolatey-toast-notifications.extension is now where I want it to be. I feel triumphant and happy. So I'll close this issue as it's all working without the need for an enhancement of BurntToast!
from burnttoast.
I would make use of such a feature.
from burnttoast.
Unfortunately I don't have a "clean" method that I've extensively tested. I need to work on some "official" guidance and am open to suggestions/requests.
The main option I've been playing with are scheduled jobs/tasks running as the user (only when logged in, so you don't need to plug in a password).
It wouldn't work in your use case (and I'm not 100% sure it'd work at all), but you could also drop a script into the user's startup folder... though this then completely hinges on the user logging in fresh at some stage.
from burnttoast.
@bcurran3 did your fix get implemented? I'm in a similar situation now where our config management creates the task as SYSTEM but the execution doesn't trigger a notification as-is.
from burnttoast.
I'm happy to help test anything.
from burnttoast.
OK. I'm still failing. Same problem. Maybe someone smarter than me can tell me what I'm doing wrong...
from burnttoast.
As far as the proof of concept, works fine when NOT trying to use the -Button parameter.
I'm guessing I need to define or pass it along differently, but I'm too ignorant.
(Keep in mind that below is missing a lot of $env variables and thus displaying blanks.)
from burnttoast.
Feeling a little smarter now....
SUCCESS!
Invoke-Command -ComputerName $env:COMPUTERNAME -ScriptBlock {New-BurntToastNotification -Text "Chocolatey ($env:chocolateyPackageName)", "$chocolateySoftwareName v$env:chocolateyPackageVersion", "Uninstalled." -Button (New-BTButton -Content 'Package Webpage' -Arguments "https://chocolatey.org/packages/$env:chocolateyPackageName") -AppLogo "$env:ChocolateyInstall\extensions\chocolatey-toast-notifications\choco.ico"}
Moving the New-BTButton creation into a result of part of the full command instead of assigning a variable to it and then passing the variable worked.
@nmcspadden, I retract my "No' answer and now say Yes. :)
...and a hint on use:
COMMENT: check for system account
if ($env:USERNAME -eq "$env:COMPUTERNAME$"){
COMMENT: WinRM needs to be running
If ((Get-Service $WinRM).Status -eq 'Running') {
Invoke-Command -ComputerName $env:COMPUTERNAME -ScriptBlock {blahblah}
}
}
COMMENT: else skip or create toast message without Invoke-Command here...
from burnttoast.
if we want to send for a specific user in an RDS collection, how can we do, thanks for your remarks
from burnttoast.
@ludovicbernard Sorry, I have not tried that and not sure. I'm guessing you'd want to figure out the list of computers in the collection and then loop through them sending each the message.
from burnttoast.
In case anyone was wondering this still works for normal toasts, but if you try it with New-BurntToastShoulderTap
you just get an empty toast from the People app, no dancing Alfonso Ribeiro.
from burnttoast.
I wonder if this is a feature or a bug that might be fixed by Microsoft at some time.
Starting the command in the SYSTEM context and ending up with a toast in the user context without even selecting the user or session. Seeing this working is a real surprise to me. Other processes will just launch in the SYSTEM context when started that way.
Is anybody aware of some piece of information concerning this behavior?
from burnttoast.
Related Issues (20)
- [Feature Request Summary] Support for mobile notifications using notify17? HOT 1
- Toast History access and Toast removal failures on PowerShell 7.1 HOT 3
- No alert sound on multiple machines, except on the first I installed to. HOT 3
- BurntToast -AppLogo does not accept valid UNC paths to WSL locations HOT 2
- Missing documentation on the ActivatedAction parameter on Submit-BTNotification function HOT 1
- empty AppLogo as default value HOT 6
- Doc: how to enable notifications HOT 2
- Typo in Example05? HOT 1
- Toast History access failure on PowerShell 7.2.1 HOT 2
- Provide a feature to read the content of currently displayed Toast Notifications HOT 4
- [Bug]: MethodInvocationException: Exception calling "Show" with "1" argument(s): "Access is denied. HOT 1
- [Bug]: Update-BTNotification not doing its job even when verbose shows no error. HOT 5
- Replace/Remove Shipped DLLs
- Allow variable names to be displayed in the toast notification HOT 1
- character limit notification text HOT 1
- New-BurntToastNotification Button Overflow Menu HOT 1
- icon and heroImage with http-URL HOT 1
- [Bug]: Basic test script does not work HOT 5
- [Bug]: Can't set button label with New-BTButton with Update-BTNotification HOT 2
- warn not to use Windows Store PowerShell
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from burnttoast.