Files
general-scripts-and-system-…/Windows-Scripts/alert.ps1
T
2026-07-18 16:27:51 -06:00

42 lines
1.2 KiB
PowerShell

# Usage: alert <message="Alert"> (<type=Information/None/Error/Question/Warning> (<Buttons=OK/OKCancel/YesNoCancel/YesNo>))
# HELP HANDLE
if($args[0] -eq 'h' -or $args[0] -eq '-h' -or $args[0] -eq 'H' -or $args[0] -eq '-H' -or $args[0] -eq 'help' -or $args[0] -eq 'Help' -or $args[0] -eq 'HELP') {
Write-Host "Usage: alert <message=Alert> (<type=Information/None/Error/Question/Warning> (<Buttons=OK/OKCancel/YesNoCancel/YesNo>))`nalert h/-h/help/etc: Display this help message"
exit
}
# MESSAGE HANDLE DEFAULT
if([string]::IsNullOrEmpty($args[0])) {
$Message = "Alert"
} else {
$Message = $args[0]
}
# TYPE HANDLE DEFAULT
if([string]::IsNullOrEmpty($args[1])) {
$Type = "Information"
} else {
$Type = $args[1]
}
# BUTTONS HANDLE DEFAULT
if([string]::IsNullOrEmpty($args[2])) {
$Buttons = "OK"
} else {
$Buttons = $args[2]
}
# doin inide start-job method so alert box doesnt block
Start-Job -ScriptBlock {
# get back my fuckin vars inside this script block
$Message = $using:Message
$Buttons = $using:Buttons
$Type = $using:Type
# Add the PresentationFramework
Add-Type -AssemblyName PresentationFramework
# Send the alert
[System.Windows.MessageBox]::Show($Message, $Message, $Buttons, $Type)
};