2010-05-18 81 views

回答

5

这绝不是唯一的方法,但这里是我使用的一种方法。这是针对PS v1的,有些代码可以针对V2进行优化。

function get-apppools{ 
    [regex]$pattern="-ap ""(.+)""" 
    gwmi win32_process -filter 'name="w3wp.exe"' | % { 
     $name=$_.name 
     $cmd = $pattern.Match($_.commandline).Groups[1].Value 
     $procid = $_.ProcessId 
     New-Object psobject | Add-Member -MemberType noteproperty -PassThru Name $name | 
      Add-Member -MemberType noteproperty -PassThru AppPoolID $cmd | 
      Add-Member -MemberType noteproperty -PassThru PID $procid 
    } 
} 

此输出:

PS C:\Documents and Settings\jpogran> get-apppools 

Name         AppPoolID                 PID 
----         ---------                 --- 
w3wp.exe        SharePoint - 9090               6988 
w3wp.exe        SharePoint - 80               6364 
w3wp.exe        foo.bar.net               4720 
w3wp.exe        SharePoint Central Administration v3          7960 
w3wp.exe        SharePoint - 8181               7756 

的iisapp脚本显示这一点:

PS C:\Documents and Settings\jpogran> iisapp 
Microsoft (R) Windows Script Host Version 5.6 
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. 

W3WP.exe PID: 6988 AppPoolId: SharePoint - 9090 
W3WP.exe PID: 6364 AppPoolId: SharePoint - 80 
W3WP.exe PID: 4720 AppPoolId: foo.bar.net 
W3WP.exe PID: 7960 AppPoolId: SharePoint Central Administration v3 
W3WP.exe PID: 7756 AppPoolId: SharePoint - 8181 
PS C:\Documents and Settings\jpogran>