Skip to content

Instantly share code, notes, and snippets.

@TylerLeonhardt
Created January 17, 2019 19:45
Show Gist options
  • Save TylerLeonhardt/a26fa9badafb585043a309d97d687146 to your computer and use it in GitHub Desktop.
Save TylerLeonhardt/a26fa9badafb585043a309d97d687146 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 ($true) {
([bool]$Urgency) { $notifySendArgs += "--urgency=$Urgency" }
([bool]$ExpireTime) { $notifySendArgs += "--expire-time=$ExpireTime" }
([bool]$Catagory) { $notifySendArgs += "--category=$($Catagory -join ',')" }
([bool]$SoundFile) { $notifySendArgs += "--hint=string:sound-file:$SoundFile" }
([bool]$Icon) {
if ($Icon -eq "powershell-logo") {
Add-DefaultPSIcon
}
$notifySendArgs += "--icon=$($Icon -join ',')"
}
Default {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment