I was testing popups with PowerShell when I noticed something weird occurring.
The icon on the left of the popup looked different compared to another method of showing it. Also, the button styles were different.
These were both run on the same system (Windows 10 Pro), and the code is exactly the same (shown below). Both were run on PowerShell 5.1.
Add-Type -AssemblyName PresentationFramework
$result = [System.Windows.MessageBox]::Show("Would you like to continue?", "Continue?", "YesNo", "Information", "No")
Write-Host $result
1. Old Icon and Buttons
The old icon and buttons were created using the typical PowerShell application. I saved the file as a .ps1
file and then ran it like usual.
$ ./test.ps1
However, it gave me this popup. It's normal, but it looks more like a Windows 7 popup than Windows 10.
2. New Icon and Buttons
The new icon and buttons were created using the Windows PowerShell ISE. It was run without saving the file (just clicked the Run button to execute it).
This gave me a popup I would expect to see on Windows 10.
So, is this behaviour expected? Also, why is it happening?
Solution
You need to add the following line to your code before the popup.
[System.Windows.Forms.Application]::EnableVisualStyles()
This will give the popup the new, modern feel to it.
Why?
The reason that this is occurring is because when running this in the PowerShell ISE, it automatically runs it with the EnableVisualStyles
option.
However, when the code is run in PowerShell, it doesn't add the EnableVisualStyles
part unless you specify so.
This is why the popup looks "older" in PowerShell, but more modern in the PowerShell ISE.