我的腳本輸出任何託管網站的文本文件。該文本文件看起來像下面這樣:從文本文件創建CSV文件
Default Settings Layouts Stackexchangelogon
我需要這些成CSV與下列頭文件:
- 類型
- 基地
- 狀態
對於Type,我需要網站名稱,Base,我需要IIS和Status,我需要監視。
最後的輸出會是這樣的,
Type Base Status Default IIS Monitored Settings IIS Monitored Layouts IIS Monitored Stackexchangelogon IIS Monitored
我已經在網上搜索,並就如何實現這一目標仍然不解。由於Windows 2003主機,它需要在PowerShell 2.0上運行。
這是我迄今爲止 -
$website = Get-content "D:\Websites.txt"
$CSV = @()
$row = New-Object System.Object
$website | ForEach-Object {
$row | Add-Member -MemberType NoteProperty -Force -Name "Type" -Value $_
$row | Add-Member -MemberType NoteProperty -Force -Name "Base" -Value "IIS"
$row | Add-Member -MemberType NoteProperty -Force -Name "Status" -Value "Monitored"
$CSV += $row
}
但它不是添加每個網站。我重複列表中的最後一個。結果:
Type Base Status ---- ---- ------ Stackexchangelogon IIS Monitored Stackexchangelogon IIS Monitored Stackexchangelogon IIS Monitored Stackexchangelogon IIS Monitored
任何想法?