VMware Cloud Community
zenivox
Hot Shot
Hot Shot
Jump to solution

output truncated

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!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I suspect you might have place the Out-GridView at the wrong location.
Like this I get all VMs in 1 view.

&{foreach ($vmi in $vmNames){

    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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

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.

foreach ($vmi in $vmNames){

   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

0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect you might have place the Out-GridView at the wrong location.
Like this I get all VMs in 1 view.

&{foreach ($vmi in $vmNames){

    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

0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

yes, I placed it inside the loop :smileysilly: thanks Luc!

0 Kudos