Display Windows

by Aug 23, 2016

PowerShell 3+

It is fairly easy to use WPF (Windows Presentation Foundation) to create and show simple dialog windows in PowerShell. If you’d like to display a quick message, check this out:

Add-Type -AssemblyName PresentationFramework

$window = New-Object Windows.Window
$window.Title = 'Warning'
$window.WindowStartupLocation = 'CenterScreen'
$window.Topmost = $true
$TextBlock = New-Object System.Windows.Controls.TextBlock
$TextBlock.Text = 'You really should stop working and get some sunshine every now and then!'
$TextBlock.Margin = 20
$window.Content = $TextBlock
$window.SizeToContent = 'WidthAndHeight'
$null = $window.ShowDialog()

Twitter This Tip! ReTweet this Tip!