Powershell:获取所有暂停的任务

我试图从运行Windows Server 2012的terminal服务器获取所有暂停的任务。

我已经尝试使用wmi对象的powershell像这样:

Get-WmiObject -Class Win32_Process -ComputerName computername -Property status 

但是所有进程的status属性都是空的,但是它显示在任务pipe理器的详细信息视图中,如下所示:

在这里输入图像描述

我也尝试了下面的代码尝试获取正在运行的线程的状态:

 $processes = Get-Process * -ComputerName ppivts | select name,threads foreach ($process in $processes) { foreach ($thread in $process.Threads) { if($thread.ThreadState -ne "Wait"){ $process.Name $thread.ThreadState } } } 

这也不pipe用。 我如何获得过程的状态,更具体地说是暂停状态?

你可以改进后面的代码片段,如下所示:

 $processes = Get-Process * $processHt = @{} # empty hash table foreach ($process in $processes) { foreach ($thread in $process.Threads) { if($thread.ThreadState -eq "Wait") { if ( $processHt.Containskey( $process.Name ) ) { if ( $processHt[$process.Name] -match $($thread.WaitReason.ToString()) ) { } else { $processHt[$process.Name] += ",$($thread.WaitReason.ToString())" } } else { $processHt.Add( $process.Name , $thread.WaitReason.ToString() ) } } } } "`n=== all threads suspended ===" $processHt.Keys | Where-Object { $processHt[$_] -eq 'Suspended' } "`n=== some thread suspended ===" $processHt.Keys | Where-Object { $processHt[$_] -match 'Suspended' } | ForEach-Object { @{ $_ = $processHt[$_] } } | Format-Table -AutoSize -HideTableHeaders # merely for simple output look 

示例输出

 PS D:\PShell> D:\PShell\SO\46546587.ps1 === all threads suspended === WWAHost === some thread suspended === System FreePage,Executive,EventPairLow,Suspended,VirtualMemory,LpcReceive,ExecutionDelay WWAHost Suspended explorer UserRequest,Executive,EventPairLow,Suspended PS D:\PShell> 

对应的任务管理器截图

对应的任务管理器截图