Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonWahlin/f8577c4604d2cdbc88e9a0262a7558fe to your computer and use it in GitHub Desktop.
Save SimonWahlin/f8577c4604d2cdbc88e9a0262a7558fe to your computer and use it in GitHub Desktop.
silly parameter checking
function Send-PSNotification {
[cmdletbinding()]
param(
[Parameter(Mandatory,ValueFromPipeline,Position=0)]
[object]
$Body,
[String]
$Summary = 'PowerShell Notification',
[ValidateSet('low', 'normal', 'critical')]
$Urgency,
[int]
$ExpireTime,
[string[]]
$Icon = "powershell-logo",
[string[]]
$Category,
[string]
[ValidateNotNullOrEmpty()]
$SoundFile
)
$notifySendArgs = switch ($PSBoundParameters.Keys) {
'Urgency' { "--urgency=$Urgency" }
'ExpireTime' { "--expire-time=$ExpireTime" }
'Catagory' { "--category=$($Catagory -join ',')" }
'SoundFile' { "--hint=string:sound-file:$SoundFile" }
'Icon' {
if ($Icon -eq "powershell-logo") {
Add-DefaultPSIcon
}
"--icon=$($Icon -join ',')"
}
Default {}
}
$notifySendArgs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment