Hello, I'm trying to fix a truncated output for a scenario where the expandProperty does not work. I searched in google but haven't found a solution to this:
foreach ($vmi in $vmNames){
Get-VM $vmi | ?{$_.Name -notlike "*CTX*" -and $_.Name -notlike "*CX*"} | Select-Object `
@{N="Name";E={$vmi | Select -ExpandProperty Name}},
@{N="Tools-Status";E={
if($_.Guest.Extensiondata.GuestState -eq "notRunning"){
"Not running"}
else{
$_.Guest.Extensiondata.ToolsVersionStatus.Replace("guestToolsNeedUpgrade","Out of date").Replace("guestToolsNotInstalled","Not installed").Replace("guestToolsCurrent","OK").Replace("guestToolsUnmanaged","Unmanaged")
}
}}
}
The name of certain VMs is truncated. I don't want the -ft because it's not useful to read for what I'm doing... I hope someone has a fix many thanks!
I suspect you might have place the Out-GridView at the wrong location.
Like this I get all VMs in 1 view.
Get-VM $vmi | ?{$_.Name -notlike "*CTX*" -and $_.Name -notlike "*CX*"} |
Select-Object Name,
@{N="Tools-Status";E={
if($_.Guest.Extensiondata.GuestState -eq "notRunning"){
"Not running"}
else{
$_.Guest.Extensiondata.ToolsVersionStatus.Replace("guestToolsNeedUpgrade","Out of date").Replace("guestToolsNotInstalled","Not installed").Replace("guestToolsCurrent","OK").Replace("guestToolsUnmanaged","Unmanaged")
}
}}
}} | out-gridview
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this.
That 1st Select with the line continuation doesn't work.
Also the Name property is present on the VirtualMAchine object, no need to use a calculated property.
Get-VM $vmi | ?{$_.Name -notlike "*CTX*" -and $_.Name -notlike "*CX*"} |
Select-Object Name,
@{N="Tools-Status";E={
if($_.Guest.Extensiondata.GuestState -eq "notRunning"){
"Not running"}
else{
$_.Guest.Extensiondata.ToolsVersionStatus.Replace("guestToolsNeedUpgrade","Out of date").Replace("guestToolsNotInstalled","Not installed").Replace("guestToolsCurrent","OK").Replace("guestToolsUnmanaged","Unmanaged")
}
}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc, thanks I already tried that at the very beginning and it didn't work. That is why I sophisticated things a bit by trying with the calculated property. There 4 or 5 VMs' name with truncated output
That works for me.
What exactly do you mean by "truncated output"?
Is it the three dots at the end of a value?
Then try with Format-List or Out-GridView
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes Luc, that is what I mean...the three dots.. fl shows each VM on a line of its own and out-gridview opens as many windows as many VMs. I guess I have to create a var that will contain the output while looping and then play with its output
I suspect you might have place the Out-GridView at the wrong location.
Like this I get all VMs in 1 view.
Get-VM $vmi | ?{$_.Name -notlike "*CTX*" -and $_.Name -notlike "*CX*"} |
Select-Object Name,
@{N="Tools-Status";E={
if($_.Guest.Extensiondata.GuestState -eq "notRunning"){
"Not running"}
else{
$_.Guest.Extensiondata.ToolsVersionStatus.Replace("guestToolsNeedUpgrade","Out of date").Replace("guestToolsNotInstalled","Not installed").Replace("guestToolsCurrent","OK").Replace("guestToolsUnmanaged","Unmanaged")
}
}}
}} | out-gridview
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes, I placed it inside the loop :smileysilly: thanks Luc!