如何从 Microsoft.IIs.PowerShell.Framework.ConfigurationElement 对象中提取文本
如果我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
绑定属性是一个集合,因此您必须使用
ExpandProperty
参数:要进一步深入:
The bindings property is a collection so you have to use the
ExpandProperty
parameter:To drill down further:
最近我正在研究类似的命令,但用于列出所有站点及其绑定。在 IIS 中,这就是我所做的:
注意替换(“`r”,“”)。如果您需要导出为 CSV,则需要它。
Recently I was working on similar command but for list all Sites and its bindings. In IIS this is what i did :
Note the replace("`r","" ). It is needed if you need to export to CSV.
如果您不想从
Get-Website
启动,还可以使用Get-WebBinding
cmdlet。这将显示所有网站的所有绑定信息,您可以从那里进一步过滤它。
以下是运行上述命令的示例输出。
There's also the
Get-WebBinding
cmdlet that can be used if you don't want to start fromGet-Website
.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.