Closed tkj365 closed 6 years ago
Hi @tkj365, you were nearly there!
The Table
function does not support calculated properties. You will need to use calculated properties with Select-Object
and then pipe the results to Table
.
[11] C:\..\Dropbox\PowerShell> Import-Module PScribo -Force;
$doc = Document Issue34 {
Get-VMHost |
Sort-Object Name |
Select-Object Name,
@{Name="Processor Count";Expression={$_.LogicalProcessorCount;}},
@{Name="Memory (GB)";Expression={[math]::Round($_.MemoryCapacity /1GB,2)}} |
## We need to select the properties required, before piping to table
Table -Name 'Example'
}
Export-Document -Document $doc -Format Text -Path . -Options @{ TextWidth = 120 } |
Get-Content
Name Processor Count Memory (GB)
---- --------------- -----------
IBLAPTOP 4 11.88
Note: the example here is using a Hyper-V host and not an ESXi host - you will need to adjust the parameter(s) accordingly!
Closing this out. If the above does not answer the question, please re-open the issue.
I am trying to get output rounded in the Table output and it seems this breaks the math functionality in Powershell. Am I missing something?
Get-VMHost | Sort Name | Table -Columns Name,Parent,NumCpu,@{Name="Memory (GB)";Expression={[math]::Round($_.MemoryTotalGB,2)}},Version -Headers 'Name','Cluster','CPU Count','Memory Capacity','ESXi Version' -Width 0
I get this result: Table : Cannot process argument transformation on parameter 'Name'. Cannot convert value to type System.String.