Posted: . At: 12:50 PM. This was 2 years ago. Post ID: 15803
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to show a pop up notification with a Powershell script.


Showing a pop-up notification from the system tray is very easy with Powershell on Windows 11.

To begin, run this command as Administrator to install the BurntToast module.

Install-Module -Name BurntToast

Then you are ready to use this script to show a sample notification.

Import-Module BurntToast
New-BurntToastNotification -Text "Windows 11 Update", "You are due for a Windows 11 update" -AppLogo 'C:\Users\Intel i5\Pictures\Windows-11-logo.jpg'

This will show the text and also a picture of your choice on the notification.

To see the last Powershell command invoked, use the Invoke-History cmdlet.

PS C:\Users\Intel i5\Documents\stuff> Invoke-History
New-BurntToastNotification -Text "Windows 11 Update", "You are due for a Windows 11 update" -AppLogo 'C:\Users\Intel i5\Pictures\Windows-11-logo.jpg'

To get an item from the Powershell history that has the ID # of 8, we do it like this.

PS C:\Users\Intel i5\Documents\stuff> Invoke-History -Id 8
New-BurntToastNotification -Text "Windows 11 Update", "You are due for a Windows 11 update" -AppLogo 'C:\Users\Intel i5\Pictures\Windows-11-logo.jpg'

The Get-Clipboard cmdlet will get the contents of the clipboard as text and print it to the terminal.

PS C:\Users\Intel i5\Documents\stuff> Get-Clipboard
PS C:\Users\Intel i5\Documents\stuff> Invoke-History -Id 8
New-BurntToastNotification -Text "Windows 11 Update", "You are due for a Windows 11 update" -AppLogo 'C:\Users\Intel i5\Pictures\Windows-11-logo.jpg'

The Invoke-WebRequest cmdlet acts rather like wget. This when used on a website will print the HTML of the web page to the terminal.

PS C:\Users\Intel i5\Documents\stuff> Invoke-WebRequest
 
cmdlet Invoke-WebRequest at command pipeline position 1
Supply values for the following parameters:
Uri: https://securitronlinux.com/maps/002.png
 
 
StatusCode        : 200
StatusDescription : OK
Content           : {137, 80, 78, 71...}
RawContent        : HTTP/1.1 200 OK
                    Connection: keep-alive
                    Cf-Bgj: imgq:85,h2pri
                    Cf-Polished: origSize=10534
                    Vary: Accept
                    X-Frame-Options: sameorigin
                    CF-Cache-Status: HIT
                    Age: 10
                    Expect-CT: max-age=604800, report...
Headers           : {[Connection, keep-alive], [Cf-Bgj, imgq:85,h2pri], [Cf-Polished, origSize=10534], [Vary, Accept]...}
RawContentLength  : 7644

Use it like this to download a file from a website.

PS C:\Users\Intel i5\Documents> Invoke-WebRequest -OutFile my.png -Uri https://securitronlinux.com/maps/002.png

A good alternative to wget on Linux, this could be a most useful cmdlet in a Powershell script. You can use aliases in Powershell just as you can in the bash shell. Use the Get-Alias cmdlet to list all current aliases in the current session. To create an alias in Powershell, use this one-liner.

PS C:\Users\Intel i5\Documents> Set-Alias -Name ll -Value Get-ChildItem

Save the custom alias in a file this way.

PS C:\Users\Intel i5\Documents> Export-Alias -Path "alias.csv"

Then once you start a new Powershell session, use this cmdlet to import the aliases.

PS C:\Users\Intel i5> Import-Alias -Force -Path .\alias.csv

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.