PowerShell::如何按用户名筛选工作进程列表
基本上,根据屏幕截图,IIS中有多个工作进程在机器上运行,但我们需要w3wp,它在Sitecore用户用户名下运行。 我们尝试了PS脚本,但在用户名列中得到了空值PowerShell::如何按用户名筛选工作进程列表,powershell,iis-8,Powershell,Iis 8,基本上,根据屏幕截图,IIS中有多个工作进程在机器上运行,但我们需要w3wp,它在Sitecore用户用户名下运行。 我们尝试了PS脚本,但在用户名列中得到了空值 $processlist = get-process | where {$_.cpu -gt 5 -and $_.Name -eq 'w3wp'} |select Name, @{l="User name";e={$_.getowner().user}} | ft -AutoSize foreach($proc in $proce
$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执行一些操作
我建议您使用以下时尚脚本,它将为您提供所有必要的信息和更多信息:
# 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."
}
Ref:工作进程属于其应用程序池,然后,您可以将池标识与要检查的用户帐户进行比较。@wp78sw这太棒了…我得到了我所期望的…现在基本上我正在从这个PS脚本执行proddump.exe,当我运行这个脚本时,我得到消息
,这是这个程序的第一次运行。您必须接受EULA才能继续。使用-accepteula接受EULA。
看起来我需要先接受协议(类似于单击“同意”按钮)才能继续操作。在运行PS时如何实现这一点script@Sukhjeevan我很高兴这个答案符合你的需要。请随意接受并投票。尽管如此,让我们继续讨论这个话题。你可能想发布一个关于你以后问题的新问题。您是否尝试添加-accepteula
或/accepteula
?见checkhttps://stackoverflow.com/questions/5151034/psexec-gets-stuck-on-licence-prompt-when-running-non-interactivelythanks @wp78de感谢您的快速帮助…我为此创建了一个新帖子