2014-02-10 37 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變量。

相關問題