发布于 2024-11-14 04:10:31 字数 8 浏览 3 评论 0原文

continue

I have some code to get a list of IIS6 sites through ADSI:

([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}

When I pipe it through the convertto cmdlets or out-string or looping through objects using tostring() I get something like this

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

Basically I just need the list of sites (servercomment) to be treated like Powershell objects so I can export them through various means. But from my understanding these are collections in themselves and do have more properties, but when I go deeper I don't see anything that can be extracted as the name of an IIS site. Is getting this info through WMI easier or do I have to create a new Powershell object to contain these?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烈酒灼喉 2024-11-21 04:10:31
 $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

This will give you an array of custom psobjects with those two child items as noteproperties, along with the string values.

 $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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文