Answered by:
User Password Notification

Question
-
I have a script that works great in ISE but when I save it and try and run it I get a really quick error starting with unable to something.
Here is the script.
Function Invoke-BalloonTip {
<#
.Synopsis
Display a balloon tip message in the system tray.
.Description
This function displays a user-defined message as a balloon popup in the system tray. This function
requires Windows Vista or later.
.Parameter Message
The message text you want to display. Recommended to keep it short and simple.
.Parameter Title
The title for the message balloon.
.Parameter MessageType
The type of message. This value determines what type of icon to display. Valid values are
.Parameter SysTrayIcon
The path to a file that you will use as the system tray icon. Default is the PowerShell ISE icon.
.Parameter Duration
The number of seconds to display the balloon popup. The default is 1000.
.Inputs
None
.Outputs
None
.Notes
NAME: Invoke-BalloonTip
VERSION: 1.0
AUTHOR: Boe Prox
#>
[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
*****
Error
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Unable to find type [System.Windows.Forms.ToolTipIcon].
At C:\scripts\password\Password_Notify.ps1:37 char:9
+ [System.Windows.Forms.ToolTipIcon]$MessageType="Info",
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Windows.Forms.ToolTipIcon:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
PS C:\Users\bmcalister\Desktop>Monday, March 26, 2018 2:03 PM
Answers
-
First you have to load the assambly with this:
[reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")
... and please format your code as code here in the forum. Thanks
Best regards,
(79,108,97,102|%{[char]$_})-join''
- Marked as answer by Brad McAlister Monday, March 26, 2018 9:22 PM
Monday, March 26, 2018 5:19 PM
All replies
-
First you have to load the assambly with this:
[reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")
... and please format your code as code here in the forum. Thanks
Best regards,
(79,108,97,102|%{[char]$_})-join''
- Marked as answer by Brad McAlister Monday, March 26, 2018 9:22 PM
Monday, March 26, 2018 5:19 PM -
Will do.
Thank You
Monday, March 26, 2018 9:22 PM