使用 PowerShell 创建气球提示通知

问题描述

我是 Powershell 的新手!

感谢所有抽出时间帮助我的人。

注意:我不是管理员,我的 POWERSHELL 在受限模式下运行 - 由于工作政策,无法更改:D

到目前为止,我有以下代码

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) 
 

遗憾的是,这在受限工作中不起作用 - 我无法使用 Add-Type 功能。对于没有管理员权限的人,是否有代码可以在受限模式下在 powershell 中允许气球类型提示通知(或任何类似的 - 只需要弹出消息)。

错误

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

如果这根本不可能,完全不用担心,有人可以澄清这一点,以便我可以告诉我的网络管理员

解决方法

对此的一种解决方案是让您的管理员将脚本添加为他们策略的例外。这将允许您批准的脚本在完整语言模式下运行。

更好的解决方案是让您的管理员在其策略例外中允许签名脚本,并让您通过从本地 CA 获取代码签名证书来对脚本进行签名。在 Windows 域中,这需要一些设置,但完成后相对容易管理。

我们阻止了域中所有未签名的脚本,并为管理员/开发人员提供了代码签名证书。