如何同时将对象输出到Powershell控制台窗口的各种坐标?

时间:2019-01-03 05:12:08

标签: powershell-v4.0

我已经在Win 10环境中使用Powershell几个月了,所以对于Powershell还是一个新手,我正在尝试使用Powershell控制台作为显示的技术要点,从而可以循环/循环遍历数据和显示的各个组成部分控制台窗口各个坐标处的信息。我的问题是,它只能在任何时间仅显示来自任何一个特定循环的数据。我怀疑将需要像运行空间或psjobs这样的多线程类型,但是我相信它们既是后台函数,也无法实时显示数据,因此不确定控制台是否支持这种请求。 也许还有另一种解决方法

我尝试将所有脚本和get-命令放在一个循环中,但是它没有提供“外观”,并且感觉不到我们正在尝试实现。我希望能够将整个窗口用作输出对象的场所。我看过psjobs和运行空间,但它们似乎在后台运行。

因此,所提供的代码应将get-service对象和get-process对象同时输出到指定的坐标。

function OBJ1{
[console]::setcursorposition(60,120)
Get-Process
]}
function OBJ2{
[console]::setcursorposition(10,70)
Get-Service
]}
Workflow obj3
{ 
Parallel 
{ 
obj1
obj2
} 
} 
obj3

相反,我得到的错误是:

<!-- language: lang-none -->
Microsoft.PowerShell.Utility\Write-Error : Exception calling "SetCursorPosition" with "2" argument(s): "The handle is invalid.
"
At obj3:20 char:20
+
    + CategoryInfo          : NotSpecified: (:) [Write-Error], RemoteException
    + FullyQualifiedErrorId : System.Management.Automation.RemoteException,Microsoft.PowerShell.Commands.WriteErrorCommand
    + PSComputerName        : [localhost]

Microsoft.PowerShell.Utility\Write-Error : Exception calling "SetCursorPosition" with "2" argument(s): "The handle is invalid.
"
At obj3:20 char:20
+
    + CategoryInfo          : NotSpecified: (:) [Write-Error], RemoteException
    + FullyQualifiedErrorId : System.Management.Automation.RemoteException,Microsoft.PowerShell.Commands.WriteErrorCommand
    + PSComputerName        : [localhost]

0 个答案:

没有答案