在 Windows Server 2012 R2 上运行 Shell 脚本并在另一个 VM 上获取 Toast 通知

问题描述

所以我正在编写一个在 Windows Server 2012 R2 上运行的 Shell 脚本。该脚本在特定时间重新启动网络中的所有虚拟机。现在我想为虚拟机用户添加一个 ToastNotification,虚拟机将在几秒钟内重新启动。这就是我目前所拥有的。

while ($null -ne $Global:vmName[$Global:counter] ){
    $vm = $Global:vmName[$Global:counter]
    Write-host "VMname $($vm)"
    
    if("$($vm)"-eq "VM-XYZ" ) {
        Write-Host "Found XYZ"
        
        Add-Type -AssemblyName System.Windows.Forms
        $global:balmsg = New-Object System.Windows.Forms.NotifyIcon
        $path = (Get-Process -id $pid).Path
        $balmsg.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
        $balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
        $balmsg.BalloonTipText = "Die VM startet in 30 Sekunden neu"
        $balmsg.BalloonTipTitle = "Achtung!"
        $balmsg.Visible = $true
        $balmsg.ShowBalloonTip(1)
    }
    $Global:counter++; 
}

我想象的应该是这样的:

while ($null -ne $Global:vmName[$Global:counter] ){
    $vm = $Global:vmName[$Global:counter]
    Write-host "VMname $($vm)"

    if("$($vm)"-eq "VM-XYZ" ) {
        Write-Host "Found XYZ"

        Add-Type -AssemblyName System.Windows.Forms
        $global:balmsg = New-Object System.Windows.Forms.NotifyIcon
        $path = (Get-Process -id $pid).Path
        $balmsg.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
        $balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
        $balmsg.BalloonTipText = "Die VM startet in 30 Sekunden neu"
        $balmsg.BalloonTipTitle = "Achtung!"
        $balmsg.Visible = $true

        **$vm.ShowBalloontip(1) 
        $vm.$balmsg.ShowBalloonTip(1)**
    }
    $Global:counter++; 
} 

我很感激我能帮我解决这个问题几个小时。我无法在互联网上找到有关该特定问题的任何答案。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)