2017-03-08 23 views
0

Output of format table
我試圖使用PSCustomObject來存儲遠程計算機的一堆信息。我似乎無法得到Format-Table的輸出以我想要的方式工作。格式表輸出來自pscustomobject的大括號中的列表

如圖所示,PSCustom對象中的項目列表顯示在大括號內,而不是列標題下的列表。

下面是我用來生成測試PSCustomObject並填充其中一個屬性的代碼。

$EnvironmentInfo = [PSCustomObject] @{Name=[System.Collections.ArrayList]@(); Description=[System.Collections.ArrayList]@(); Publisher=[System.Collections.ArrayList]@(); Doggo=[System.Collections.ArrayList]@()} 

$EnvironmentInfo.Name.Add("Doggo") 
$EnvironmentInfo.Name.Add("Doggo") 
$EnvironmentInfo.Name.Add("Doggo") 
$EnvironmentInfo.Name.Add("Doggo") 
$EnvironmentInfo.Name.Add("Doggo") 
$EnvironmentInfo.Name.Add("Doggo") 
$EnvironmentInfo.Name.Add("Doggo") 
$EnvironmentInfo.Name.Add("Doggo") 
$EnvironmentInfo.Name.Add("Doggo") 

$EnvironmentInfo | Format-Table -Property $_ 
+1

你爲什麼這樣做的,而不是'$ EnvironmentInfo = @([PSCustomObject] @ {名稱= '名字1';描述= '說明1';出版商=「發佈者1 '; Doggo ='Doggo 1'}; [PSCustomObject] @ {Name ='Name 2'; Description ='Description 2'; Publisher ='Publisher 2'; Doggo ='Doggo 2'})'? – PetSerAl

+0

請顯示您所需的輸出。 –

+0

@PetSerAl我想我可以以某種方式管Get-Hotfix到一個pscustomobject數組中,只是感覺不對 – Fullmetal99012

回答

0

你的問題很簡單,留下很多想象力。不過,它看起來像要從多個來源收集一系列信息並將其組合起來,以便生成整齊的格式化輸出。我可以提供一個可能(或不可以)幫助你的例子。該示例從多臺機器收集HotFix信息(每個@PetSerAI),並返回每個修補程序的對象,並將其傳送到格式表中。

<# 
.Synopsis 
    Gather HotFix Info 
.DESCRIPTION 
    Gather HotFix Info from one or more computers 
.EXAMPLE 
    @("LCFSQL01","LCFSQL02","LCFSQL03","LCFSQL05") | Gather-HotFixInfo 
    Gathers info for several remote machines 
.EXAMPLE 
    Gather-HotFixInfo -Machine = "LCFSQL01" 
    Gathers info for a single remote machine 
#> 
Function Gather-HotFixInfo 
{ 
    [CmdletBinding()] 
    Param 
    (
     # Machine remote machine name 
     [Parameter(Mandatory=$true, 
        ValueFromPipeline=$true, 
        Position=0)] 
     [string]$Machine 
    ) 
    Process 
    { 
     Try 
     { 
      Get-HotFix -ComputerName $machine | ForEach-Object { 
       [pscustomobject]@{Name=$_.CSName; 
        Description=$_.Description; 
        HotFixID=$_.HotFixID; 
        Doggo="Doggo"} 
      }  
     } 
     Catch 
     { 
      Write-Warning "Could not connect to $machine" 
     }   
    } 
} 

# List of all computers from which to gather info 
@("LCFSQL01","LCFSQL02","LCFSQL03","LCFSQL05") | Gather-HotFixInfo | Format-Table 

Formatted Output

相關問題