[英]GUI and PSRemoting in Powershell CLI
最近,我創建了一個腳本,該腳本利用了GUI(例如Out-GridView和Winforms)並將該模塊放在遠程Windows 2012服務器上。 這是為了允許用戶從集中位置建立遠程PSSession並執行腳本。
例如:
1.嘗試調用winform時出現以下錯誤:
Exception calling "ShowDialog" with "0" argument(s): "Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style
to display a notification from a service application."
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException
+ PSComputerName : servera
2.嘗試將結果放入Out-GridView時,出現以下錯誤:
Out-GridView does not work in a remote session.
+ CategoryInfo : InvalidOperation: (Microsoft.Power...GridViewCommand:OutGridViewCommand) [Out-GridView], NotSupportedException
+ FullyQualifiedErrorId : RemotingNotSupported,Microsoft.PowerShell.Commands.OutGridViewCommand
+ PSComputerName : servera
題:
有什么變通辦法可以讓我利用OGV和Winforms嗎?
旁注:我願意允許用戶將模塊導出到他們的物理工作站,以允許他們在需要的情況下使用這些選項-OGV和Winforms-僅在有有效/安全措施的情況下才可以使用。我願意接受不同的建議。
您需要在本地計算機上而不是遠程計算機上使用UI。 遠程檢索數據,在本地顯示。
例如:
Invoke-Command -ComputerName RemoteServer -Scriptblock { Get-Process } | Out-Gridview
在腳本塊中使用gridview將嘗試在RemoteServer上啟動UI,並給您提到的錯誤。
我認為Invoke-Command
會更好,因為您是在告訴遠程計算機該怎么做,而不是要求使用Enter-PSSession
或New-PSSession
與遠程計算機直接進行交互。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.