简体   繁体   English

在richtextbox中显示表格输出

[英]Show tabular output in richtextbox

Just installed the PowerShell Studio and I'm trying to view the results of some VMware commands in a richtextbox. 刚刚安装了PowerShell Studio,我正在尝试在richtextbox中查看某些VMware命令的结果。

When I run the get-vm , for example, it shows the data fine (I changed the font to Lucida Console- and it looks ok), regular get-vm results in the richtext box: 例如,当我运行get-vm ,它显示数据正常(我将字体更改为Lucida Console-它看起来没问题),常规get-vm结果在richtext框中:

Name : xxx
Cluster : xxx
ESX Host : esx6
Datastore : xxx
MemoryGB : 8
NumCpu : 2
ProvisionedSpace(GB) : 282
UsedSpace(GB) : 281
OS : Microsoft Windows Server 2008 R2 (64-bit)

But when I try to run (get-vm).Guest.Disks the data not shown good in the richtextbox, it looks like this: 但是当我尝试运行(get-vm).Guest.Disks(get-vm).Guest.Disks中显示不好的数据时,它看起来像这样:

Capacity:192515403776,
FreeSpace:43895230464,
Path:E:\

Capacity:75053920256,
FreeSpace:12630409216,
Path:C:\

when run it in regular powershell console it look like it should: 在常规的PowerShell控制台中运行时,它看起来应该是:

Volume Capacity(GB) FreeSpace(GB) % FreeSpace
------ ------------ ------------- -----------
E:\    120          13            11
C:\    120          15            12

The command line in PowerShell is: PowerShell中的命令行是:

((Get-VM $vm).Guest.disks) | Format-Table @{N="Volume";E={$_.Path}},
    @{N="Capacity(GB)";E={[System.Math]::Round($_.CapacityGB)};a="left"},
    @{N="FreeSpace(GB)";E={[System.Math]::Round($_.FreeSpaceGB)};a="left"},
    @{N="% FreeSpace";E={[math]::Round((100 * ($_.FreeSpacegb / $_.Capacitygb)),0)};a="left"} -auto |
  Out-String

the command line in the richtextbox is: richtextbox中的命令行是:

$richtextbox1.AppendText((Get-VM $text).Guest.disks) |
  Format-Table @{N="Volume";E={$_.Path}},
    @{N="Capacity(GB)";E={[System.Math]::Round($_.CapacityGB)};a="left"},
    @{N="FreeSpace(GB)";E={[System.Math]::Round($_.FreeSpaceGB)};a="left"},
    @{N="% FreeSpace";E={[math]::Round((100 * ($_.FreeSpacegb / $_.Capacitygb)),0)};a="left"} -auto |
 Out-String 

How can I get the results like it looks in the PowerShell console wheter is with richtextbox or any other control? 如何在PowerShell控制台中查看带有richtextbox或任何其他控件的结果?

Looks like your richtextbox gives you the results in list format. 看起来您的richtextbox以列表格式提供结果。 Pipe your results into the Format-Table cmdlet before piping it into Out-String to enforce table format: 将结果传递到Format-Table cmdlet,然后将其传递到Out-String以强制执行表格格式:

... | Format-Table | Out-String

您需要使用以下固定大小字体之一来显示输出:Consolas Courier New Lucida Console

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM