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コマンドレットまたはout-stringを介してパイプするか、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"

基本的に、サイトのリスト(servercomment)をPowershellオブジェクトのように扱う必要があるので、さまざまな方法でそれらをエクスポートできます。しかし、私の理解では、これらはそれ自体がコレクションであり、より多くのプロパティがありますが、深く掘り下げると、IISサイトの名前として抽出できるものは何も表示されません。WMIを介してこの情報を取得するのは簡単ですか、それともこれらを含む新しいPowershellオブジェクトを作成する必要がありますか?

4

1 に答える 1

4

これにより、文字列値とともに、これら2つの子アイテムをnotepropertiesとして持つカスタムpsobjectの配列が得られます。

 $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 に答える