Automation

 View Only
  • 1.  Receiving Output in different format

    Posted Feb 07, 2018 09:01 AM

    Hi all,

    I am new to Powercli.

    I want retrieve all the VMs details whose Guest OS is Linux. SO I executed the following command and obtained the nearly correct output. But the output format is different. Can anyone help me?

    get-vm | select-object name, Guest, powerstate | select-string 'linux' -simplematch

    Output: (which I receive)

    But I want the output in following format:



  • 2.  RE: Receiving Output in different format

    Posted Feb 07, 2018 09:05 AM

    You can use a Where-clause for that

    Get-VM | where{$_.Guest -match 'linux'} |Select-Object name, Guest, powerstate



  • 3.  RE: Receiving Output in different format

    Posted Feb 07, 2018 09:14 AM

    Hello LucD,

    Thank you for your response.

    I have tried using where clause. But problem is in 'Guest' column, the value is not just 'linux'. There are some other characters are present front and back of the word linux. For reference, please see the 'guest' column in the following screenshot.

    So if I use,

    Get-VM | where{$_.Guest -match 'linux'} |Select-Object name, Guest, powerstate

    No output is displayed. I have also tried the same script in following way but no luck.

    Get-VM | where{$_.Guest -match '*linux*'} |Select-Object name, Guest, powerstate



  • 4.  RE: Receiving Output in different format
    Best Answer

    Posted Feb 07, 2018 09:31 AM

    The -match operator expects a RegEx expression in the right-side operator.

    In my code, it will search for the string 'linux', independent if there are other characters before or after it.

    So there is no point in adding the asterisk, that is only a meta-character for the -like operator when used like that


    It looks as if you didn't install the VMware Tools on all your VMs, so the OSFullName will not be available for those VMs.

    And hence the match will fail.
    Also note that for powered off VMs, the info might not be available

    Can you check if the OSFullName is available on all your VMs

    Get-VM |

    Select Name,

        @{N='GuestId';E={$_.Guest.GuestId}},

        @{N='OSFullName';E={$_.Guest.OSFullName}}

    Another option is to check for the GuestId, but that is unreliable since you can specify that it is a Linux box, and still install a Windows Guest OS on there.

    The following will filter a number of Linux guests, including SLES VMs.

    Get-VM | where{$_.Guest.GuestId -match 'linux|sles'} |Select-Object name, Guest, powerstate



  • 5.  RE: Receiving Output in different format

    Posted Feb 07, 2018 09:40 AM

    Hi LuCD,

    thank you so much.  Actually -match operator worked for me. i got the required output