【问题标题】:PowerShell - showing a message on remote computer screenPowerShell - 在远程计算机屏幕上显示消息
【发布时间】:2021-01-23 17:49:02
【问题描述】:

当我使用 PowerShell - Invoke-Command 等远程运行命令或安装软件时,我有时希望能够在远程屏幕上显示一条消息,以便用户知道发生了什么事情,或者工作何时完成等。

如果可能的话,我希望让这条消息看起来尽可能专业,例如如果可以做到,比标准的winform消息框更好吗?如果可能的话,可能更像是带有彩色背景和使用图像的 Windows 10 风格。

花了一段时间谷歌搜索,但大多数似乎与使用过时的方法有关,例如 net-send 或使用 msg.exe。

谢谢

【问题讨论】:

    标签: powershell powershell-remoting


    【解决方案1】:

    https://michlstechblog.info/blog/powershell-show-a-messagebox/

    所以问题真的不在于创建消息框本身,而是让它显示在用户会话中。

    因此,当您对系统运行命令时,您是在使用您的凭据来运行该命令,因此它不会显示在用户会话中。您可以通过使用任务调度程序在用户上下文中运行它来解决此问题。我有一个脚本可以为您完成所有这些工作,但是,我讨厌重新创建轮子,并且必须等到星期一(当我在工作时)才能将其发布在这里。

    它在您的会话中接受用户输入,然后将其输出到 vbs,然后通过消息将其复制到用户计算机,并且任务计划设置为立即为登录的用户运行。

    edit:脚本是没有任务调度程序的。我只是调用gwmi win32_computersystem | Select -ExpandProperty username 来让当前用户登录并将其添加到任务中。

    #Prompt for messge
    $strMSG = Read-Host -Prompt "Enter message"
    
    #deleting vbs if it exists
    del C:\brief\test.vbs
    
    #creating vbs from scratch so it doesnt override
    New-Item C:\brief\test.vbs
    
    #Appending each the values to a seperate line
    Add-Content C:\brief\test.vbs 'Set objShell = Wscript.CreateObject("WScript.Shell")' 
    Add-Content C:\brief\test.vbs "strText = `"$strMSG`"" 
    Add-Content C:\brief\test.vbs 'intButton = objShell.Popup(strText,0,"Computer Support",48)'
    
    #calling on the script
    & cscript C:\brief\test.vbs
    

    【讨论】:

    • 谢谢亚伯拉罕 - 这是一个有趣的方式,会看看
    【解决方案2】:

    在这里找到了一个很好的解决方案,它出现在快速测试中,可以很好地在远程机器上显示 toast 通知

    https://smsagent.blog/2019/06/11/just-for-fun-send-a-remote-toast-notification/

    【讨论】:

      猜你喜欢
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      • 2012-05-22
      相关资源
      最近更新 更多