我在創建遠程PowerShell彈出消息時遇到了一些問題。遠程PowerShell彈出消息給所有不工作的用戶
我有一個工作腳本,顯示我想要發送給遠程用戶的彈出消息。但是,無論何時將它捆綁到.ps1腳本中並遠程運行,它都不會向登錄用戶發送彈出消息。我知道腳本運行正常,因爲腳本的其他部分正確執行。我能夠在本地機器上運行彈出消息,所以它不是腳本錯誤。
的腳本是:
Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Form.Text = 'ALERT!'
$form.ControlBox = $false;
$Image = [system.drawing.image]::FromFile('\\filepath')
$Form.BackgroundImage = $Image
$Form.BackgroundImageLayout = 'Stretch'
$Form.Width = (680)
$Form.Height = (550)
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(500,445)
$OKButton.Size = New-Object System.Drawing.Size(100,50)
$OKButton.Text = 'Accept'
$OKButton.Font = New-Object System.Drawing.Font('Times New Roman',18)
$OKButton.Add_Click({$Form.Close()})
$Form.Controls.Add($OKButton)
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()
我跑這是一個被稱爲在以下時尚的.ps1的一部分:
Invoke-WmiMethod -Class Win32_Process -ComputerName $computer -Name Create -ArgumentList "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe \\$computer\C$\folder\script.ps1
我運行腳本作爲服務帳戶來自執行Windows 7企業臺式機上的命令的服務器。目標機器執行策略設置爲不受限制,因此我知道這不是腳本執行策略問題。
我有一個預感,它不在目標機器上彈出的原因是因爲運行腳本的帳戶和登錄到目標機器的帳戶是不同的,但我可能是不正確的。
你需要描述你是如何遠程運行它的。我懷疑這種方法無效,但請編輯您的問題以指定。 – briantist
我建議使用msg.exe代替。你可以使用Powershell來包裝它,就像這個人一樣。 [Send-NetMessage](https://gallery.technet.microsoft.com/scriptcenter/Send-NetMessage-Net-Send-0459d235) –