2014-02-10 43 views
1

我想知道是否有人有Powershell脚本分享。获取IIS7中所有网站的列表?

我想的是,从IIS7导出所有的网站,以CSV以下值文件的脚本:

名称,网址,端口

例子:

Testapp,www.testapp.com,80

我试着用Get-Website出口,但出口到CSV时,我得到的只有名字,其余输出这样Microsoft.IIs.PowerShell.Framework.ConfigurationElement

谦逊的问候,
Tobbe

回答

2

像这样的东西应该做的伎俩:

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变量。

相关问题