1 2 Previous Next 24 Replies Latest reply on Aug 30, 2019 7:15 AM by veera1987 Go to original post
      • 15. Re: Complete VM information
        ganapa2000 Hot Shot

        Hi LucD,

         

        How can I export output of this script to CSV format.

         

        Also, I am not able to get the Folder details of the VM. Please help LucD Guru

        • 16. Re: Complete VM information
          veera1987 Novice

          Hi Luc,

           

          Please provide me the complete script to run in Multiple vcenter servers

          • 17. Re: Complete VM information
            LucD Guru
            Community WarriorsvExpertUser Moderators

            Try like this

             

            foreach ($vc in $global:DefaultVIServers)

            {

               foreach ($vm in (Get-View -Server $vc -ViewType VirtualMachine -Property Name, runtime.powerState, Guest.net, Config.Hardware.numCPU, Config.Hardware.MemoryMB, Runtime.Host, Guest.GuestFullName,

              Config.GuestFullName, Parent, ResourcePool, Config.Hardware.Device, Config.version, guest.toolsversionstatus,

              Config.Files.VMPathName))

               {

               $t = Get-View -Id $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 { $_.GetType().Name -eq "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 = '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 = "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 = "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 -Server $vc -ViewType DistributedVirtualPortgroup -Property Name -Filter @{'Key' = $_.Backing.Port.PortgroupKey } |

              Select -ExpandProperty Name

               } })) }

               }

               }

            }

            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
            • 18. Re: Complete VM information
              veera1987 Novice

              Hi LuCD,

               

              Script is working fine but if the server has 2 disks then it displayed 2 times. Can we export into CSV format in which multiple hard disk are added in new row.

              • 19. Re: Complete VM information
                LucD Guru
                User ModeratorsvExpertCommunity Warriors

                Are those entries really duplicates?
                Aren't properties like Unit, Filename... different?

                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                • 20. Re: Complete VM information
                  veera1987 Novice

                  Hi LuCD,

                   

                  It has different name and not duplicates. Is there any way that the script will get the resourcepool details. SInce while i am running with 2 vcenter server received error on resourcepool with below error.

                  Get-View : Cannot validate argument on parameter 'Id'. The argument is null or

                  empty. Provide an argument that is not null or empty, and then try the command

                  again.

                  At C:\Temp\VMInfo-Latest.ps1:14 char:22

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

                  +                      ~~~~~~~~~~~~~~~~

                      + CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingVal

                     idationException

                      + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom

                     ation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

                  Please help!!!

                  • 21. Re: Complete VM information
                    LucD Guru
                    Community WarriorsvExpertUser Moderators

                    Do you know for which VM this error is being generated?

                    Could it be a Template?

                    With Get-View -ViewType VirtualMachine you get VMs and also Templates.

                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                    • 22. Re: Complete VM information
                      veera1987 Novice

                      Hi LuCD,

                       

                      Yes i hope it is checking Template but is there a way to pull the template as well. I would like to know whether we can pull Summary details (Model, Processor types, Uptime, State) of all ESXi host along with the utilization. Also i noticed that the ESxi host that are in maintenance mode are not pulled in the output. Can we get that as well.

                      • 23. Re: Complete VM information
                        LucD Guru
                        vExpertUser ModeratorsCommunity Warriors

                        This is going way beyond the orginal question in this thread.

                        May I suggest to open a new thread.

                        Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                        • 24. Re: Complete VM information
                          veera1987 Novice

                          Hi LuCD,

                           

                          Sorry for the delayed response, I have already opened a new thread named "Complete Inventory". Request your help on the same.

                          1 2 Previous Next