我想用完整的字符串显示输出

时间:2017-03-29 04:14:21

标签: powershell powercli

Connect-VIServer XXXX

[System.Collections.ArrayList]$Result=@()
$vms = Get-VM | Where-Object {$_.Name -like 'XXX*'}
try{
 ForEach ($v in $vms)
  {
   foreach ($d in $v.ExtensionData.Guest.Disk)
    {
    $usedSpace = $d.Capacity - $d.FreeSpace
    $percentUsed =  [math]::Round(($usedSpace / $d.Capacity) * 100)

    $List = New-Object -TypeName PSObject -Property @{
        SERVER_NAME = $v.Name | Out-String
            "Total_Capacity(GB)" = [math]::round([int]($d.Capacity/1GB), 1)
            "Free_Space(GB)" = [math]::round([int]($d.FreeSpace/1GB), 1)
            PercentFull = "$percentUsed%"
                        }
                #Write-Host "$ErrorList"
            $Result+=$List
    }
  }
}
catch [Exception]
{
write-host "OD-VM-Monitor: $v : FATAL SCRIPT ERROR" $_.Exception.Message
}

我已经执行了上面的脚本。但在尝试显示结果时,它会显示如下点所示。我试过以下两个。

$Result | Select-Object SERVER_NAME, 'Total_Capacity(GB)', 'Free_Space(GB)', PercentFull | Out-String -Width 4096 | ft -auto
$Result | Select-Object SERVER_NAME, 'Total_Capacity(GB)', 'Free_Space(GB)', PercentFull | Format-Table -AutoSize

SERVER_NAME     Total_Capacity(GB) Free_Space(GB) PercentFull
-----------     ------------------ -------------- -----------
XXXXXXX...                200            113 43%
XXXXXXX...                150             50 67%
XXXXXXX...                150             31 79%
XXXXXXX...                100             32 68%
XXXXXXX...                500             87 83%
XXXXXXX...                100             43 57%
XXXXXXX...                100             36 64%
XXXXXXX...                150             37 75%

任何想法如何摆脱困境。 提前谢谢。

2 个答案:

答案 0 :(得分:0)

这是因为字符串对于您的屏幕来说太宽(控制台窗口)。 尝试使用format-list而不是format-table来确认数据没有被破坏。

这是一个以编程方式和通过GUI更改大小的指南:https://blogs.technet.microsoft.com/heyscriptingguy/2006/12/04/how-can-i-expand-the-width-of-the-windows-powershell-console/

答案 1 :(得分:0)

Format-Table可以hash table指定列宽。