6 Replies Latest reply on Mar 25, 2014 9:21 AM by GlenTrust

    Get Guestos trough Powercli

    mkool89 Novice

      Hi all,

       

      I wrote below script to get all Vm's in my Vcenters that don't have vmware tools installed. i am trying to include the vm's / guests operating system into the csv output as well and can't seem to figure out how to do this. So if someone could help me out that would be great!

       

      New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine ` -ValueFromExtensionProperty 'Guest.ToolsVersionStatus' ` -Force
      New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine ` -ValueFromExtensionProperty 'Config.tools.ToolsVersion' ` -Force
      $vcenter=Read-Host "Please enter VCenter to run this report on"
      $csvlocation=Read-Host "Please enter a location for the CSV logfile"
      Connect-ViServer $vcenter
      $notools = Get-VM | where-Object {$_.ToolsVersionStatus -eq "guestToolsNotInstalled"}
      if ( $notools -eq $null) {
      exit
      }
      else {
      Get-VM $notools | Select Name, Version, ToolsVersion, ToolsVersionStatus, powerstate, vmhost, | Export-Csv -NoTypeInformation -UseCulture $csvlocation\$vcenter.csv
      }
      Disconnect-VIServer $vcenter -Confirm:$False
      
      

       

      Thanks in advance

        • 1. Re: Get Guestos trough Powercli
          mattboren Master
          vExpert

          Hello, -

           

          You can access such info via a sub-property in the Guest property of the VirtualMachine object.  So, to continue with your New-VIProperty usage, you could add another new VIProperty as follows, then add that property to the Select statement:

           

          New-VIProperty -Name GuestFullName -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.GuestFullName' -Force

           

          Then just add "GuestFullName" to the list of properties in your Select statement, and you should be good.  That do it for you?

          • 2. Re: Get Guestos trough Powercli
            mkool89 Novice

            Thanks for the help, this sort off did the trick. Some vm's are not showing their os version but that is not because of the new vi property.

            Going to try and figure out why that is now

            • 3. Re: Get Guestos trough Powercli
              mattboren Master
              vExpert

              Hello, mkool89-

               

              Alright, good, glad to help.  As for VMs not showing their OS version -- that is reliant upon VMware Tools running in the guest.  So, if Tools aren't running (or haven't been for a while), you might see the symptom of no data for that Guest OS property.  Do the VMs in your example that return no OS info also not have Tools running?

              • 4. Re: Get Guestos trough Powercli
                mkool89 Novice

                mattboren,

                 

                I didn't know that the property was dependandt on vmwaretools being installed. It makes sense now that it doesn't display since my script displays all VM's withouth tools installed! At least i learned something !

                 

                I have one more question: is there a place where i can see al the viproperty's that can be added? I am having dificulties with finding  properties and what they do.

                 

                Thanks

                • 5. Re: Get Guestos trough Powercli
                  mattboren Master
                  vExpert

                  Hello-

                   

                  Yesss, good to hear (I learn at least one thing every day!).

                   

                  As for a place to see what VIProperties can be added:  it's really about what properties are available.  The vSphere API reference documentation shows all of the properties/methods that you can leverage.  vSphere Web Services SDK:  http://www.vmware.com/support/developer/vc-sdk/.  And, in particular, the vSphere API Reference:  http://pubs.vmware.com/vsphere-55/topic/com.vmware.wssdk.apiref.doc/right-pane.html.

                   

                  Check those out, and made whatever VIProperties you want!  Meanwhile, LucD (of course) has a nice collection of VIProperties that he and others have written:  http://www.lucd.info/viproperties/.  Check it out.

                  • 6. Re: Get Guestos trough Powercli
                    GlenTrust Novice

                    Hi,

                     

                    Im trying to do something similar, but im running into some problems tho.

                     

                    First of all, i would like to just count how many VM's are running linux as guest OS, this i have done by using this command:

                     

                    Get-VM | Select-Object Name, PowerState, NumCpu, MemoryMB, ProvisionedSpaceGB, Guest | Where-Object {$_.Guest.OSFullName -like "*Linux*"}

                     

                    And i get list back of 6 VM's but when i go to my vSphere Client and list all VM's, filter them on GuestOS containing Linux, i have 14 VM's

                     

                    Why are the Powershell CLI only counting 6, when there are 14 in total? Does this also have something to do with vmWare Tools not running on the VM's? or is this something else?

                     

                    Edit:

                     

                    I solved it. I belive its because the above line does not look at what the VM's OS have been selected to be the time it was build. But that is only what i belive

                     

                    I solved it with this instead:

                     

                    $vms = get-vm

                    foreach($vm in $vms) {

                    $vmview = $vm | get-view

                    if ($vmview.Summary.Config.GuestFullName -like "*Windows*") {$wincount++}

                    }

                    $wincount

                     

                    This will count the real amount of VM's that have some kind of Windows OS configured.

                     

                    Message was edited by: GlenTrust