I'm missing something. I've been working on this on and off for the past couple of days and can't figure out what I'm doing wrong here. My goal is to ultimately develop an audit script for my environment using the VI Toolkit.
$scReserved = @{ Label = "Reserved"; Expression = { (Get-View -id (Get-View $_).ConfigManager.MemoryManager).ConsoleReservationInfo.ServiceConsoleReserved) } }
Get-VMHost | ft Name,$scReserved
This doesn't work.
I have a way to get this info by doing the following though i'd like to be able to use Format-Table instead. Why doesn't this work and what am I missing in how to do these Expressions?
This works though isn't a friendly to save out to a file or to use Format-Table.
$hosts = Get-VMHost | Get-View
foreach($hostview in $hosts) {
$mem Get-View -id $hostview.ConfigManager.MemoryManager
$h = $hostview.Name + ","+ $mem.ConsoleReservationInfo.ServiceConsoleReserved
Write-Host $h
}
Please Powershell me correctly.
The curly braces and parenthesis were not balanced
This sample will do what I think you were trying to do
$scReserved = @{Label = "Reserved"; Alignment = "Left"; Expression={(Get-View -Id $_.ConfigManager.MemoryManager).ConsoleReservationInfo.ServiceConsoleReserved}} Get-VMHost | Where-Object {$_.State -eq "Connected"} | Get-View | ft @{Label = "Name"; Expression = {$_.Name}; Width = 20}, $scReserved
Note that I added a Where-Object cmdlet to the pipe since you can't get the reserved memdory value for hosts that are not connected.
To show that the hash table table is used for formatting the objects I added some other keys (Alignment, Width) to the hash table.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The curly braces and parenthesis were not balanced
This sample will do what I think you were trying to do
$scReserved = @{Label = "Reserved"; Alignment = "Left"; Expression={(Get-View -Id $_.ConfigManager.MemoryManager).ConsoleReservationInfo.ServiceConsoleReserved}} Get-VMHost | Where-Object {$_.State -eq "Connected"} | Get-View | ft @{Label = "Name"; Expression = {$_.Name}; Width = 20}, $scReserved
Note that I added a Where-Object cmdlet to the pipe since you can't get the reserved memdory value for hosts that are not connected.
To show that the hash table table is used for formatting the objects I added some other keys (Alignment, Width) to the hash table.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference