3

我有一些代码可以通过 ADSI 获取 IIS6 站点列表:

([adsi]"IIS://localhost/W3SVC").psbase.children | select servercomment, serverstate | Where-Object {$_.serverstate -ne $null}

servercomment                                               serverstate
-------------                                               -----------
{Default Web Site}                                          {4}
{SharePoint Web Services}                                   {4}
{SharePoint Central Administration v4}                      {4}
{SharePoint - 80}                                           {4}

当我通过 convertto cmdlet 或输出字符串或使用 tostring() 循环对象时,我得到类似这样的东西

#TYPE Selected.System.DirectoryServices.DirectoryEntry
"servercomment","serverstate"
"System.DirectoryServices.PropertyValueCollection","System.DirectoryServices.PropertyValueCollection"
"System.DirectoryServices.PropertyValueCollection","System.DirectoryServices.PropertyValueCollection"
"System.DirectoryServices.PropertyValueCollection","System.DirectoryServices.PropertyValueCollection"
"System.DirectoryServices.PropertyValueCollection","System.DirectoryServices.PropertyValueCollection"

基本上我只需要像 Powershell 对象一样对待站点列表(servercomment),这样我就可以通过各种方式导出它们。但是据我了解,这些本身就是集合,并且确实具有更多属性,但是当我更深入时,我看不到任何可以提取为 IIS 站点名称的内容。通过 WMI 获取这些信息更容易还是我必须创建一个新的 Powershell 对象来包含这些信息?

4

1 回答 1

4

这将为您提供一个自定义 psobjects 数组,其中两个子项作为 noteproperties,以及字符串值。

 $x = ([adsi]"IIS://localhost/W3SVC").psbase.children |
  select @{l="ServerComment";e={[string]$_.servercomment}},
    @{l="ServerState";e={[string]$_.Serverstate}} | 
    where {$_.serverstate}
$x.count
2
$x[0]

ServerComment                                               ServerState
-------------                                               -----------
Default Web Site                                            2


$x[0] | gm


   TypeName: Selected.System.DirectoryServices.DirectoryEntry

Name          MemberType   Definition
----          ----------   ----------
Equals        Method       bool Equals(System.Object obj)
GetHashCode   Method       int GetHashCode()
GetType       Method       type GetType()
ToString      Method       string ToString()
ServerComment NoteProperty System.String ServerComment=Default Web Site
ServerState   NoteProperty System.String ServerState=2
于 2011-06-08T12:39:15.980 回答