我有一些代码可以通过 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 对象来包含这些信息?