PowerCLI

 View Only
  • 1.  Get all VMs with Running OS Like Linux or Other Script

    Posted Feb 22, 2017 05:46 PM

    Having a hard time here...how do i return results for just linux and OS's called "Other" instead of just all OSs. I have the script below:

    get-vm |  Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="Powered On";E={ $_.PowerState -eq “PoweredOn”}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}} | Export-CSV -NoTypeInformation C:\Users\iaasadmin\Desktop\getvms.csv

    Any ideas to add the filter to just return Linux and Other OSs?

    Thank you



  • 2.  RE: Get all VMs with Running OS Like Linux or Other Script

    Posted Feb 22, 2017 05:52 PM

    Try like this

    Get-VM |

    where{$_.ExtensionData.Config.GuestFullname -notmatch "win"} |

    Select Name,

        @{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},

        @{N="Running OS";E={$_.Guest.OsFullName}},

        @{N="Powered On";E={ $_.PowerState -eq “PoweredOn”}},

        @{N="disktype";E={(Get-Harddisk $_).Storageformat}}



  • 3.  RE: Get all VMs with Running OS Like Linux or Other Script

    Posted Feb 22, 2017 06:00 PM

    I agree with Luc. Some linux distributions do not list their OS correctly, whereas I haven't run across a situation where Windows OS is incorrect. I will typically use something like the below to operate on windows machines. If you're looking to gather non-windows you can just negate the if clause, or use an else.

    foreach($objCluster in Get-Cluster){
       
    foreach ($objvm in $($objCluster|get-vm)){
             
    if($objvm.guestid.contains("windows")){
                 
    #### windows actions or data collection goes here
              }else{
                 
    ### non-windows actions or data collection goes here
              }
        }
    }


  • 4.  RE: Get all VMs with Running OS Like Linux or Other Script

    Posted Aug 28, 2019 03:19 PM

    This was exactly what I needed, LucD​! I removed some of the parameters, but it was perfect. Thanks, as always!



  • 5.  RE: Get all VMs with Running OS Like Linux or Other Script

    Broadcom Employee
    Posted Feb 22, 2017 05:53 PM

    Modify your query as given below:

    get-vm |  Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="Powered On";E={ $_.PowerState -eq “PoweredOn”}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}} | Where { ($_."Configured OS").contains("Other") -or ($_."Configured OS").contains("Linux") } | Export-CSV -NoTypeInformation C:\Users\iaasadmin\Desktop\getvms.csv