检查 RunspacePool 是否已经在机器上打开
Check whether a RunspacePool is already open on a machine
我有一个在 VM 上 运行s Powersell 脚本的进程。此脚本在 VM 上定义了一个 RunspacePool,并根据该 VM 的资源能力设置阈值(运行空间的数量)。这个过程是重复发生的,所以我不希望它在该 VM 上已经定义和打开一个 RunspacePools 时继续定义和打开 RunspacePools
在 Powershell 脚本的开头,我尝试通过调用 RunspacePoolStateInfo 或 RunspacePoolAvailability 属性来检查 Runspacepool 是否已定义/打开。但是这些都没有被识别,因为 Runspacepool 对象本身在进程打开到 运行 脚本
的新 window 中不可用
我基本上是在寻找一种方法来使用 Powershell 脚本识别 RunspacePool 在 VM 上是否打开
PowerShell V5 及更高版本的答案
您可以通过运行
获取当前进程中的Runspaces
Get-Runspace
或者如果你知道名字
Get-Runspace -Name <name>
PowerShell V5 中的远程运行空间
如果您要检查的运行空间在另一个进程中,您必须先执行此操作。
Enter-PSHostProcess -Id <int>
或
Enter-PSHostProcess -Process <ProcessObject>
我有一个在 VM 上 运行s Powersell 脚本的进程。此脚本在 VM 上定义了一个 RunspacePool,并根据该 VM 的资源能力设置阈值(运行空间的数量)。这个过程是重复发生的,所以我不希望它在该 VM 上已经定义和打开一个 RunspacePools 时继续定义和打开 RunspacePools
在 Powershell 脚本的开头,我尝试通过调用 RunspacePoolStateInfo 或 RunspacePoolAvailability 属性来检查 Runspacepool 是否已定义/打开。但是这些都没有被识别,因为 Runspacepool 对象本身在进程打开到 运行 脚本
的新 window 中不可用我基本上是在寻找一种方法来使用 Powershell 脚本识别 RunspacePool 在 VM 上是否打开
PowerShell V5 及更高版本的答案
您可以通过运行
获取当前进程中的RunspacesGet-Runspace
或者如果你知道名字
Get-Runspace -Name <name>
PowerShell V5 中的远程运行空间
如果您要检查的运行空间在另一个进程中,您必须先执行此操作。
Enter-PSHostProcess -Id <int>
或
Enter-PSHostProcess -Process <ProcessObject>