如何从 Microsoft.IIs.PowerShell.Framework.ConfigurationElement 对象中提取文本

发布于 2025-01-05 02:39:57 字数 977 浏览 1 评论 0原文

如果我在 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

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

If I run the command in powershell:

C:\Get-Website

it outputs

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

But if I try to select just the Bindings:

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

It returns:

bindings : Microsoft.IIs.PowerShell.Framework.ConfigurationElement

How do I extract the contents of this object into a useful format?

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

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

发布评论

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

评论(3

空城缀染半城烟沙 2025-01-12 02:39:57

绑定属性是一个集合,因此您必须使用 ExpandProperty 参数:

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

要进一步深入:

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

The bindings property is a collection so you have to use the ExpandProperty parameter:

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

To drill down further:

get-website -name "Default Web Site" | select -ExpandProperty Bindings | Select -ExpandProperty Collection
顾冷 2025-01-12 02:39:57

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

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

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

Recently I was working on similar command but for list all Sites and its bindings. In IIS this is what i did :

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

Note the replace("`r","" ). It is needed if you need to export to CSV.

苏璃陌 2025-01-12 02:39:57

如果您不想从 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

There's also the Get-WebBinding cmdlet that can be used if you don't want to start from Get-Website.

Import-Module WebAdministration

Get-WebBinding

This will display all of the binding info for all websites, and you can filter it down further from there.

Here's sample output of running the above command.

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