We are trying to notify our users that there will be a password policy being put in place by using the script below. It keeps erroring out with the error below. Below the error is the script we are trying to get working.
-----------------------------error------------------------------------------
Unable to find type [System.Windows.Forms.ToolTipIcon].
At line:37 char:9
-
[System.Windows.Forms.ToolTipIcon]$MessageType="Info",
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (System.Windows.Forms.ToolTipIcon:TypeName) , RuntimeException
- FullyQualifiedErrorId : TypeNotFound
---------------Script--------------------------------------------
Function Invoke-BalloonTip {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True,HelpMessage="The message text to display. Keep it short and simple.")]
[string]$Message,
[Parameter(HelpMessage="The message title")]
[string]$Title="Attention $env:username",
[Parameter(HelpMessage="The message type: Info,Error,Warning,None")]
[System.Windows.Forms.ToolTipIcon]$MessageType="Info",
[Parameter(HelpMessage="The path to a file to use its icon in the system tray")]
[string]$SysTrayIconPath='C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe',
[Parameter(HelpMessage="The number of milliseconds to display the message.")]
[int]$Duration=1000
)
Add-Type -AssemblyName System.Windows.Forms
If (-NOT $global:balloon) {
$global:balloon = New-Object System.Windows.Forms.NotifyIcon
#Mouse double click on icon to dispose
[void](Register-ObjectEvent -InputObject $balloon -EventName MouseDoubleClick -SourceIdentifier IconClicked -Action {
#Perform cleanup actions on balloon tip
Write-Verbose 'Disposing of balloon'
$global:balloon.dispose()
Unregister-Event -SourceIdentifier IconClicked
Remove-Job -Name IconClicked
Remove-Variable -Name balloon -Scope Global
})
}
#Need an icon for the tray
$path = Get-Process -id $pid | Select-Object -ExpandProperty Path
#Extract the icon from the file
$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($SysTrayIconPath)
#Can only use certain TipIcons: [System.Windows.Forms.ToolTipIcon] | Get-Member -Static -Type Property
$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]$MessageType
$balloon.BalloonTipText = $Message
$balloon.BalloonTipTitle = $Title
$balloon.Visible = $true
#Display the tip and specify in milliseconds on how long balloon will stay visible
$balloon.ShowBalloonTip(30000)
Write-Verbose "Ending function"
}
Invoke-BalloonTip -Message ‘Your Password will Expire on Friday, April 6th. If you have reset your Password within 10 days you will not be prompted to change’ -Title ‘Attention!’ -MessageType Info