Last week (12-13-14 of November 2026) there was an outage of Microsoft Office 365 solutions … So I came to an idea to quickly and efficiently notify all users that IT department know about the problem and that we are available via mobile number in case of any need.
So here is a Powershell script that will popup a message box to your users on their desktops (it is sent to all computers in a domain) to calm them down … ๐
Popup looks something like this:

Import-Module ActiveDirectory -ErrorAction Stop# Message settings$title = "Urgent message from IT department!"$message = "IT department is sending this message as our communications systems (mail / instant messaging) are not working. In case of need please call: 123123123"$timeout = 600# OUs to search, including all their sub-OUs$searchBases = @( "OU=Computers,OU=MainBuilding,DC=domain,DC=local" "OU=Computers,OU=RemoteBuildings,DC=domain,DC=local" "OU=Computers,OU=SpecialOU,DC=domain,DC=local")# Find enabled Windows computers$computers = @( @( foreach ($searchBase in $searchBases) { Get-ADComputer ` -SearchBase $searchBase ` -SearchScope Subtree ` -Filter { Enabled -eq $true -and OperatingSystem -like "Windows*" } ` -Properties DNSHostName ` -ErrorAction Stop } ) | Where-Object { $_.DNSHostName } | Sort-Object DNSHostName -Unique)Write-Host "Found $($computers.Count) computers."# Code executed remotely on each computer$remoteScript = { param($Title, $Message, $TimeoutSeconds) if (-not ("ClassroomMessage" -as [type])) { Add-Type -TypeDefinition @"using System;using System.ComponentModel;using System.Runtime.InteropServices;public class ClassroomMessage{ [DllImport("wtsapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] static extern bool WTSSendMessage( IntPtr hServer, int SessionId, string pTitle, int TitleLength, string pMessage, int MessageLength, int Style, int Timeout, out int pResponse, bool bWait ); [DllImport("kernel32.dll")] static extern uint WTSGetActiveConsoleSessionId(); public static string Show(string title, string message, int timeout) { uint sessionId = WTSGetActiveConsoleSessionId(); if (sessionId == 0xFFFFFFFF) return "Skipped: no console session attached"; int response; bool success = WTSSendMessage( IntPtr.Zero, (int)sessionId, title, title.Length * 2, message, message.Length * 2, 0x00000030 | 0x00040000, timeout, out response, false ); if (!success) throw new Win32Exception(Marshal.GetLastWin32Error()); return "Message submitted"; }}"@ -ErrorAction Stop } [ClassroomMessage]::Show($Title, $Message, $TimeoutSeconds)}# Connection timeout in milliseconds$sessionOptions = New-PSSessionOption -OpenTimeout 5000# Send sequentially; continue if a computer is unreachable$index = 0$results = foreach ($computer in $computers) { $index++ $target = $computer.DNSHostName Write-Host "[$index/$($computers.Count)] Sending to $target ..." try { $status = Invoke-Command ` -ComputerName $target ` -ScriptBlock $remoteScript ` -ArgumentList $title, $message, $timeout ` -SessionOption $sessionOptions ` -ErrorAction Stop [PSCustomObject]@{ Computer = $target Status = $status } } catch { [PSCustomObject]@{ Computer = $target Status = "Failed: $($_.Exception.Message)" } }}# Show results$results | Format-Table -AutoSize -Wrap
You can try to see how your message will look like directly on your PC by running this code:
$title = "Urgent message from IT department!"$message = "IT department is sending this message as our communications systems (mail / instant messaging) are not working.`n`n In case of need please call: 123123123"$timeout = 600Add-Type -TypeDefinition @"using System;using System.ComponentModel;using System.Runtime.InteropServices;public class LocalMessage{ [DllImport("wtsapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] static extern bool WTSSendMessage( IntPtr hServer, int SessionId, string pTitle, int TitleLength, string pMessage, int MessageLength, int Style, int Timeout, out int pResponse, bool bWait ); [DllImport("kernel32.dll")] static extern uint WTSGetActiveConsoleSessionId(); public static string Show(string title, string message, int timeout) { uint sessionId = WTSGetActiveConsoleSessionId(); if (sessionId == 0xFFFFFFFF) return "No active console session found."; int response; bool success = WTSSendMessage( IntPtr.Zero, (int)sessionId, title, title.Length * 2, message, message.Length * 2, 0x00000030 | 0x00040000, timeout, out response, false ); if (!success) throw new Win32Exception(Marshal.GetLastWin32Error()); return "Message submitted."; }}"@[LocalMessage]::Show($title, $message, $timeout)









