2015-02-08 41 views
1

我有一個計算機名稱列表,我想將此列表轉換爲4列輸出的HTML。當我在我的控制檯中輸入我的$Computerlist | format-wide -column 4時,我可以在4列中獲得格式良好的輸出。Convertto-html多列

但是,當我嘗試將其轉換爲HTML:$Computerlist | format-wide -column 4 | Convertto-html它只是返回一個空白頁。

而沒有格式化$Computerlist | Convertto-html我得到我的計算機名稱列表,但在一列中。

+1

您希望列表佔用4列,或者您只需要額外的4列空值? – Matt 2015-02-08 16:56:58

+1

你能告訴我們什麼$ ComputerList實際上是?對象或其類型的示例? – 2015-02-08 17:08:52

+0

大家好,感謝您的快速回放。 @Bill,'$ computerlist'包含我的AD'Get-Adcomputer -filter *'中的所有計算機,有超過5k個計算機帳戶。@ Matt,我只需要將我的5k計算機對象輸出分爲4列,而不是一 – kekimian 2015-02-08 17:19:32

回答

0

我正在試圖刪除所創建,你將最有可能不希望頭,但這裏是Format-Wide輸出創建對象,以滿足ConvertTo-HTML

$columns = 5 
$formatWideOutput = (Get-Process | Format-Wide -Column $columns | Out-String) -split "`r`n" 
$formatWideOutput | Where-Object{$_} | ForEach-Object{ 
    $rowData = ([string]$_).Trim() -split '\s{2,}' 
    $row = @{} 
    For($rowIndex = 0;$rowIndex -lt $columns;$rowIndex++){ 
     $row.Add("Column$($rowIndex)",$rowData[$rowIndex]) 
    } 
    [pscustomobject]$row 
} | ConvertTo-Html | Set-Content c:\temp\test.html 

需求的操縱上述示例使用Get-Process進行輸入,但在測試後可更改爲$Computerlist

Format-Wide的輸出被轉換爲換行符分隔的字符串。然後,每個row被分成一組空白區域以創建5個項目。從這些作品中製作[pscustomobject]