【问题标题】:Get a list of all websites in IIS7?获取 IIS7 中所有网站的列表?
【发布时间】:2014-02-10 10:06:46
【问题描述】:

我想知道是否有人要分享一个 Powershell 脚本。

我想要的是一个脚本,它将所有网站从 IIS7 导出到具有以下值的 CSV 文件:

名称、URL、端口

示例:

Testapp, www.testapp.com, 80

我尝试使用Get-Website 导出,但在导出为 CSV 时,我只得到名称,其余输出类似于 Microsoft.IIs.PowerShell.Framework.ConfigurationElement

谦虚的问候,
托比

【问题讨论】:

    标签: powershell iis-7


    【解决方案1】:

    这样的事情应该可以解决问题:

    Import-Module webAdministration # Required for Powershell v2 or lower  
    
    $filepath = #your_output_filepath
    $sites = get-website
    
    foreach($site in $sites) {
        $name = $site.name
        $bindings = $site.bindings.collection.bindinginformation.split(":")
        $ip = $bindings[0]
        $port = $bindings[1]
        $hostHeader = $bindings[2]
        "$name,$hostHeader,$ip,$port" | out-host
        "$name,$hostHeader,$ip,$port" | out-file $filePath -Append
    }
    

    在其中也包含了站点绑定地址,如果不需要,请从输出中省略 $ip 变量。

    【讨论】:

      猜你喜欢
      • 2022-01-02
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多