PowerCLI

 View Only
  • 1.  output truncated

    Posted Dec 16, 2019 01:10 PM

    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!



  • 2.  RE: output truncated

    Posted Dec 16, 2019 01:18 PM

    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")

            } 

        }} 

    } 



  • 3.  RE: output truncated

    Posted Dec 16, 2019 04:24 PM

    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



  • 4.  RE: output truncated

    Posted Dec 16, 2019 04:28 PM

    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



  • 5.  RE: output truncated

    Posted Dec 16, 2019 04:46 PM

    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



  • 6.  RE: output truncated
    Best Answer

    Posted Dec 16, 2019 04:52 PM

    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



  • 7.  RE: output truncated

    Posted Dec 16, 2019 05:00 PM

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