PowerShell ::如何通过用户名过滤工作进程列表 [英] PowerShell :: How to filter worker processes list by User Name

查看:96
本文介绍了PowerShell ::如何通过用户名过滤工作进程列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,根据屏幕截图,IIS中的计算机上正在运行多个工作进程,但我们需要在 Sitecore用户用户名下运行的w3wp. 我们尝试使用以下PS脚本,但在用户名

Basically as per screen-shot there are multiple worker processes are running on machine in IIS but we need w3wp which is running under Sitecore User Username. We tried below PS script but getting blank value in User Name column

$processlist  = get-process  | where {$_.cpu -gt 5 -and $_.Name -eq 'w3wp'} |select Name, @{l="User name";e={$_.getowner().user}} | ft -AutoSize
foreach($proc in $processlist){
if($proc -eq "Sitecore User" ){
     C:\Users\Administrator\Documents\someexe.exe $proc.Id "C:\Users\Administrator\Documents\output.dmp" 
     }
}

最后,我们需要对流程ID执行一些操作.

and finally we need to perform some action on process Id.

推荐答案

我建议以下PoSh脚本为您提供所有必要的信息以及更多信息:

I suggest the following PoSh-Script that should give you all the necessary info and more:

# Ensure to import the WebAdministration module
Import-Module WebAdministration

# Declare the variables
$server = "localhost"
$search = "*"

$wmiQuery=[wmisearcher]"SELECT * FROM __Namespace where NAME like 'WebAdministration' or NAME like 'MicrosoftIISv2'"
$wmiQuery.Scope.Path = "\\" + $server + "\root"
$WebNamespace = $wmiQuery.Get()

# Checking if the the server has IIS installed
if($WebNamespace -like '*WebAdministration*')
{
    "IIS  found on $server"
    $WPlist=Get-WmiObject -NameSpace 'root\WebAdministration' -class 'WorkerProcess' -ComputerName 'LocalHost'
    # Loop through the list of active IIS Worker Processes w3wp.exe and fetch the PID, AppPool Name and the startTime

    forEach ($WP in $WPlist)
    {
        if ($WP.apppoolname -like$search)
        {
           write-host "Found:""PID:"$WP.processid  "AppPool_Name:"$WP.apppoolname
           (get-process -ID $WP.processid|select starttime)
        }
    }
}
Else
{
   write-host"WARNING: IIS not detected."
}

引用: https://blogs.msdn.microsoft.com/webtopics/2015/11/28/query-the-active-worker-process-information-in-iis-7- x-using-powershell/

这篇关于PowerShell ::如何通过用户名过滤工作进程列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆