Search code examples
powershellpowershell-2.0powershell-3.0powershell-4.0powershell-remoting

Creating a Balloon Tip Notification Using PowerShell


I am new to powershell!

Thank you to anyone who takes the time out of their day and can kindly help me with this.

NOTES: I AM NOT AN ADMINSTRATOR AND MY POWERSHELL IS RUNNING IN CONSTRAINED MODE - IT CANNOT BE CHANGED DUE TO WORK POLICY :D

I have the following code so far:

Add-Type -AssemblyName  System.Windows.Forms 
$global:balloon = New-Object System.Windows.Forms.NotifyIcon 
Get-Member -InputObject  $Global:balloon 
[void](Register-ObjectEvent  -InputObject $balloon  -EventName MouseDoubleClick  -SourceIdentifier IconClicked  -Action {

  #Perform  cleanup actions on balloon tip

  $global:balloon.dispose()

  Unregister-Event  -SourceIdentifier IconClicked

  Remove-Job -Name IconClicked

  Remove-Variable  -Name balloon  -Scope Global

}) 
$path = (Get-Process -id $pid).Path

  $balloon.Icon  = [System.Drawing.Icon]::ExtractAssociatedIcon($path) 
[System.Windows.Forms.ToolTipIcon] | Get-Member -Static -Type Property
$balloon.BalloonTipIcon  = [System.Windows.Forms.ToolTipIcon]::Warning 
$balloon.BalloonTipText  = 'What do you think of this balloon tip?'

  $balloon.BalloonTipTitle  = "Attention  $Env:USERNAME"
$balloon.Visible  = $true 
$balloon.ShowBalloonTip(5000) 
 

Sadly this does not work in constrained work - I cannot use the Add-Type function. Is there a code that allows balloon type tip notifications (or anything similar - just need a pop up message) in powershell in constrained mode FOR people with no admin rights.

Error:

Cannot invoke method. Method invocation is supported only on core types in this language mode.

If this is not possible at all, no worries at all, can someone please clarify this so I can tell my network adminstrator.


Solution

  • One solution to this is to get your administrator to add the script as an exception to their policy. This will allow your approved script to run in Full Language mode.

    The better solution is for your administrator to allow signed scripts in their policy exceptions and for you to sign your scripts by obtaining a Code Signing certificate from your local CA. On a Windows domain this takes a little setting up but once done is relatively easy to administer.

    We block all unsigned scripts on our domain and Admins/Developers are given Code Signing certificates.