微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在 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 举报,一经查实,本站将立刻删除。