Bubble tip fails when deployed as login script

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

Please format your code :). Instructions are above the posting text box.

The difficulty you often run into with logon scripts is that the user profile and system aren’t yet fully loaded at that time. It can cause all kinds of weird, transient problems. Looks like you’ve asked at User notification script already and not had any love ;). Personally, I try to stay away from login scripts and user interaction of any kind for this reason.

This particular problem is one I’ve seen before, and as near as I can tell it just comes down to the system condition at the time of login. You could try explicitly loading System.Windows.Forms to see if that helps, or just give up on setting the icon.