【问题标题】:PowerShell :: How to filter worker processes list by User NamePowerShell :: 如何按用户名过滤工作进程列表
【发布时间】:2018-04-21 12:46:04
【问题描述】:

基本上,根据屏幕截图,IIS 中的机器上正在运行多个工作进程,但我们需要在 Sitecore 用户 用户名下运行的 w3wp。 我们在 PS 脚本下尝试过,但在 User Name 列中得到空白值

$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 执行一些操作。

【问题讨论】:

标签: powershell iis-8


【解决方案1】:

我建议使用以下 PoSh 脚本,它可以为您提供所有必要的信息和更多信息:

# 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/

【讨论】:

  • @wp78sw 这太棒了......我得到了我所期望的......现在基本上我正在从这个 PS 脚本执行 proddump.exe,当我运行这个脚本时,我收到了消息 This is the first run of this program. You must accept EULA to continue. Use -accepteula to accept EULA.看起来我需要先接受协议(一种同意按钮点击)才能继续进行,我们如何在运行 PS 脚本时实现这一点
  • @Sukhjeevan 我很高兴这个答案符合您的需求。随意接受和投票。尽管如此,让我们留在话题上。您可能想发布一个关于您以后的问题的新问题。您是否尝试添加-accepteula/accepteula?见检查https://stackoverflow.com/questions/5151034/psexec-gets-stuck-on-licence-prompt-when-running-non-interactively
  • 感谢@wp78de 的快速帮助....我已经为stackoverflow.com/questions/49991777/…创建了一个新帖子@
猜你喜欢
  • 2020-06-18
  • 1970-01-01
  • 1970-01-01
  • 2020-11-14
  • 2018-03-15
  • 1970-01-01
  • 1970-01-01
  • 2022-10-14
  • 1970-01-01
相关资源
最近更新 更多