1 2 3 Previous Next 36 Replies Latest reply on Mar 22, 2019 10:31 PM by LucD Go to original post
      • 15. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
        arbelac Novice

        Normally I am using this powercli script the first time.

        • 16. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          I suspect that error was caused by templates in the environment.

          I added logic to distinguish between Templates and VMs.

          Try this one

           

           

          $report = foreach($vc in $global:defaultviservers){

              foreach($vm in (Get-View -ViewType VirtualMachine -Property Name,runtime.powerState,runtime.consolidationNeeded,Guest.net,Config.Hardware.numCPU,Config.Hardware.MemoryMB,

              Runtime.Host,Guest.GuestFullName, Config.GuestFullName,Parent,ResourcePool,Config.Hardware.Device,Config.version,Config.Tools.ToolsVersion,guest.toolsversionstatus,

              Config.Files.VMPathName,Config.Template -Server $vc )){

                  if($vm.Config.Template){

                      $t = Get-View -Id (Get-View $vm.Runtime.Host).Parent

                  }

                  else{

                      $t = Get-View $vm.ResourcePool -Property Name,Parent -Server $vc

                      while($t.getType().Name -eq "ResourcePool"){

                        $t = Get-View $t.Parent -Property Name,Parent -Server $vc

                      }

                  }

                  if($t.GetType().Name -eq "ClusterComputeResource"){

                      $cluster = $t.Name

                  }

                  else{

                      $cluster = "Stand Alone Host"

                  }

                  while($t.getType().Name -ne "Datacenter"){

                      $t = Get-View $t.Parent -Property Name,Parent -Server $vc

                  }

                  $datacenter = $t.Name

              

                  $vm.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualDisk]} |

                  Select @{N="VM";E={$vm.Name}},

                  @{N='powerState';E={$vm.runtime.powerState}},

                  @{N='IP';E={[string]::Join(',',($vm.Guest.Net | %{$_.IpAddress | where{$_.Split('.').Count -eq 4} | %{$_}}))}},

                  @{N='NumCPU';E={$vm.config.Hardware.NumCpu}},

                  @{N='Memory GB';E={$vm.Config.Hardware.MemoryMB| %{[math]::Round($_/1kb,2)}}},

                  @{N='vCenter';E={$vc.Name}},

                  @{N='VMHost';E={$script:esx = Get-View -Id $vm.Runtime.Host -Server $vc ; $script:esx.name}},

                  @{N='GuestOS';E={$vm.Guest.GuestFullName}},

                  @{N='ConfiguredOS';E={$vm.Config.GuestFullName}},

                  #@{N="Folder";E={$path}},

                  @{N="Cluster";E={$cluster}},

                  @{N="Datacenter";E={$datacenter}},

                  @{N="Scsi";E={$_.UnitNumber}},

                  @{N="Hard Disk";E={$_.DeviceInfo.Label}},

                  @{N="Disk datastore";E={$_.Backing.Filename.Split(']')[0].TrimStart('[')}},

                  @{N='Needs Consolidation';E={$vm.Runtime.consolidationNeeded}},

                  @{N="Disk capacity GB";E={$_.CapacityInKB| %{[math]::Round($_/1MB,2)}}},

                  @{N="Disk type";E={

                          if($_.Backing.GetType().Name -match "flat"){

                              "Flat"

                          }

                          else{

                              $_.Backing.CompatibilityMode

                          }}},

                @{N='DeviceName';E={

                  if($_.Backing.GetType().Name -match 'raw'){

                    $_.Backing.DeviceName

                  }

                  else{

                    $script:lunnaa = (Get-View -Id $_.Backing.Datastore -Server $vc ).Info.Vmfs.Extent[0].DiskName

                    $script:lun = $script:esx.Config.StorageDevice.ScsiLun | where{$_.CanonicalName -eq $script:lunnaa}

                    $script:lun.Descriptor | where{$_.Id -match 'vml.'} | Select -ExpandProperty Id

                  }}},

                @{N='LUN NAA';E={

                  if($_.Backing.GetType().Name -match 'raw'){

                    $lunUuid = $_.Backing.LunUuid

                    $script:lun = $script:esx.Config.StorageDevice.ScsiLun | where{$_.Uuid -eq $lunUuid}

                    $script:lun.CanonicalName

                  }

                  else{

                    $script:lunnaa

                  }}},

                @{N='LUN ID';E={

                    $dev = $script:esx.Config.StorageDevice.PlugStoreTopology.Device | where {$_.Lun -eq $script:lun.Key}

                    $script:esx.Config.StorageDevice.PlugStoreTopology.Path | where {$_.Device -eq $dev.Key} |

                    Select -First 1 -ExpandProperty LunNumber

                  }},

                @{N='VMConfigFile';E={$VM.config.files.VMpathname}},

                @{N='VMDKPath';E={$_.Backing.FileName}},

                @{N="HW Version";E={$vm.Config.version}},

                @{N="VMware Tools version";E={$vm.Config.Tools.ToolsVersion}},  

                @{N="Tools Status";E={$vm.guest.toolsversionstatus}},

                @{N="NIC Name";E={($vm.config.hardware.device | where {($_.DeviceInfo.Label -like "Network*")}).DeviceInfo.Label}},

                @{N="Mac"; E={($vm.Config.Hardware.Device | where{$_.DeviceInfo.Label -like "Network*"}).MacAddress}},

                @{N="Portgroup"; E={

                  $nic = $vm.Config.Hardware.Device | where{$_.DeviceInfo.Label -like "Network*"}

                  [string]::Join(',',(

                    $nic | %{

                    if($_.DeviceInfo.Summary -notmatch 'DVSwitch'){

                      $_.DeviceInfo.Summary

                    }

                    else{

                      Get-View -ViewType DistributedVirtualPortgroup -Property Name -Filter @{'Key'=$_.Backing.Port.PortgroupKey} -Server $vc  |

                      Select -ExpandProperty Name

                    }}))}}

              }

          }

           

          $report | Export-Csv report.csv -NoTypeInformation -UseCulture

           

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 17. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
            arbelac Novice

            looks like its works good. But I am able to get the ip address, but its null for all the virtual machines. How come its null ?

             

            @{N='IP';E={[string]::Join(',',($vm.Guest.Net | %{$_.IpAddress | where{$_.Split('.').Count -eq 4} | %{$_}}))}},



            Thanks in advance.

            • 18. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              If you don't have the VMware Tools installed on the VM, the IPAddress property might be empty.

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 19. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                arbelac Novice

                This is very weird Because I can not see guest IP addresses for all Vms. Already installed VMware tools on all VMs. But I can retrieve IP addresses via RvTools.

                • 20. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                  LucD Guru
                  Community WarriorsUser ModeratorsvExpert

                  Did you restart the guest OS of the VM after the VMware Tools installation?

                   

                  Does this return IP address(es) for all VMs?

                   

                  Get-VM |

                  Select Name,@{N='IP';E={$_.ExtensionData.Guest.IPAddress -join '|'}}

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 21. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                    arbelac Novice

                    No luck  not returning any value. This is very frustrating.  How am i going to troubleshoot this?

                    • 22. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                      LucD Guru
                      User ModeratorsCommunity WarriorsvExpert

                      Do you see the IP address in the vSphere client or the Web client?

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 23. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                        arbelac Novice

                        I can see IP address via vsphere client no issue

                        • 24. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                          LucD Guru
                          User ModeratorsCommunity WarriorsvExpert

                          Are you using IPv6 by any chance?

                          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                          • 25. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                            arbelac Novice

                            We are not using IPv6 address

                            • 26. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                              LucD Guru
                              User ModeratorsCommunity WarriorsvExpert

                              Then I'm at my wits end I'm afraid

                               

                              So you see the IP address(es) in the Web Client, but the following doesn't show the IP address(es).

                               

                              Get-VM |

                              Select Name,@{N='IP';E={$_.ExtensionData.Guest.IPAddress -join '|'}}


                               

                              I have no explanation for that behaviour, nor can I recreate that I'm afraid.

                              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                              • 27. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                                arbelac Novice

                                Hi Luc,

                                 

                                I have identified very strange something. I assuming this issue is smells like a BUG regarding VMware vSphere PowerCLI 6.3 Release 1. Because I am running same command on VMware vSphere PowerCLI 5.5 Release 2 Patch 1  And I am able to see IPs for all of those VMs. What do you think about this? Or  is there any different syntax for PowerCLI 6.3 ?

                                 

                                Thanks and

                                Kind Regards,

                                • 28. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                                  LucD Guru
                                  User ModeratorsvExpertCommunity Warriors

                                  Well, I ran the same script with PowerCLI 6.3R1 against vSphere 5.5 and 6.0, and in both cases I had the IP addresses in the report.

                                  The syntax should the same, we are accessing a vSphere object, nothing to do with PowerCLI.

                                   

                                  Are you using the same PowerShell version in both environments?

                                  What does $psversiontable say?

                                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                  • 29. Re: PowerCLI Report :Getting inventory VMs from ESX cluster hosts
                                    arbelac Novice

                                    PowerCLI 6.3R1  :

                                     

                                    PowerCLI C:\> $psversiontable

                                     

                                     

                                    Name                           Value

                                    ----                           -----

                                    PSVersion                      5.0.10586.117

                                    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

                                    BuildVersion                   10.0.10586.117

                                    CLRVersion                     4.0.30319.34209

                                    WSManStackVersion              3.0

                                    PSRemotingProtocolVersion      2.3

                                    SerializationVersion           1.1.0.1

                                     

                                    PowerCLI  5.5 R2 patch 1 on another vCenter Server  :

                                     

                                    PowerCLI C:\> $psversiontable

                                     

                                     

                                    Name                           Value

                                    ----                           -----

                                    PSVersion                      4.0

                                    WSManStackVersion              3.0

                                    SerializationVersion           1.1.0.1

                                    CLRVersion                     4.0.30319.34209

                                    BuildVersion                   6.3.9600.17400

                                    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}

                                    PSRemotingProtocolVersion      2.2