【问题标题】:how to extract the text from a Microsoft.IIs.PowerShell.Framework.ConfigurationElement object如何从 Microsoft.IIs.PowerShell.Framework.ConfigurationElement 对象中提取文本
【发布时间】:2012-02-14 17:36:58
【问题描述】:

如果我在 powershell 中运行命令:

C:\Get-Website

输出

Name             ID   State      Physical Path                  Bindings
----             --   -----      -------------                  --------
Default Web Site 1               %SystemDrive%\inetpub\wwwroot  http *:80:
                                                                net.tcp 808:*
                                                                net.pipe *
                                                                net.msmq localhost
                                                                msmq.formatname 
                                                                localhost

但如果我尝试只选择绑定:

C:\Get-Website | where {$_.Name -eq "Default Web Site"} | select Bindings

返回:

bindings : Microsoft.IIs.PowerShell.Framework.ConfigurationElement

如何将此对象的内容提取为有用的格式?

【问题讨论】:

    标签: powershell iis-7


    【解决方案1】:

    bindings 属性是一个集合,所以你必须使用ExpandProperty 参数:

    Get-Website -Name "Default Web Site" | select -ExpandProperty Bindings
    

    进一步深入分析:

    get-website -name "Default Web Site" | select -ExpandProperty Bindings | Select -ExpandProperty Collection
    

    【讨论】:

    • @toryan 很高兴这对您有所帮助。如果回答了您的问题,请将我的回答标记为已接受。谢谢。
    【解决方案2】:

    最近我正在处理类似的命令,但要列出所有站点及其绑定。在 IIS 中,这就是我所做的:

    get-childItem | 
    select * , @{Name="SiteBindings"; Expression = {($_.Bindings.Collection | %{$_.protocol + "  " + $_.BindingInformation} | Out-String).replace("`r","" ) }}
    

    注意替换("`r","")。如果您需要导出为 CSV,则需要它。

    【讨论】:

      【解决方案3】:

      如果您不想从Get-Website 开始,也可以使用Get-WebBinding cmdlet。

      Import-Module WebAdministration
      
      Get-WebBinding
      

      这将显示所有网站的所有绑定信息,您可以从那里进一步过滤。

      这是运行上述命令的示例输出。

      protocol             : http
      bindingInformation   : *:80:
      sslFlags             : 0
      isDsMapperEnabled    : False
      certificateHash      :
      certificateStoreName :
      ItemXPath            : /system.applicationHost/sites/site[@name='Default Web Site' and @id='1']
      RunspaceId           : b7052f71-a213-437c-a97f-00fb9fa84a7f
      Attributes           : {Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute,
                             Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute,
                             Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute,
                             Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute…}
      ChildElements        : {}
      ElementTagName       : binding
      Methods              : {Microsoft.IIs.PowerShell.Framework.ConfigurationMethod,
                             Microsoft.IIs.PowerShell.Framework.ConfigurationMethod,
                             Microsoft.IIs.PowerShell.Framework.ConfigurationMethod,
                             Microsoft.IIs.PowerShell.Framework.ConfigurationMethod…}
      Schema               : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多