VMware Cloud Community
esxi1979
Expert
Expert

Master inventory for VM ... all info we can pull from vcenter for VM

   Hi,

      I like the script of kunal...

1. b4 trying it, can anyone else let me know if anyone tested it, i did found some typo in the script .

2. Anything else we can add in this ?

#http://kunaludapi.blogspot.com/2013/12/extended-vm-inventory-using-powercli.html#.U5VPSijiiyc

Add-PSSnapin vmware.vimautomation.core

Connect-Viserver ab1vc101.gid.gap.com  

function Get-VMinventory { 

function Get-RDMDisk { 

   [CmdletBinding()] 

   param ( 

     [Parameter(Mandatory=$True)] 

     [string[]]$VMName 

     ) 

         $RDMInfo = Get-VM -Name $VMName | Get-HardDisk -DiskType RawPhysical, RawVirtual 

         $Result = foreach ($RDM in $RDMInfo) { 

          "{0}/{1}/{2}/{3}"-f ($RDM.Name), ($RDM.DiskType),($RDM.Filename), ($RDM.ScsiCanonicalName)    

         } 

         $Result -join (", ") 

function Get-vNicInfo { 

   [CmdletBinding()] 

   param ( 

     [Parameter(Mandatory=$True)] 

     [string[]]$VMName 

     ) 

         $vNicInfo = Get-VM -Name $VMName | Get-NetworkAdapter 

         $Result = foreach ($vNic in $VnicInfo) { 

           "{0}={1}"-f ($vnic.Name.split("")[2]), ($vNic.Type) 

         } 

         $Result -join (", ") 

function Get-InternalHDD { 

   [CmdletBinding()] 

   param ( 

     [Parameter(Mandatory=$True)] 

     [string[]]$VMName 

     ) 

         $VMInfo = Get-VMGuest -VM $VMName # (get-vm $VMName).extensiondata 

         $InternalHDD = $VMInfo.ExtensionData.disk  

         $result = foreach ($vdisk in $InternalHDD) { 

           "{0}={1}GB/{2}GB"-f ($vdisk.DiskPath), ($vdisk.FreeSpace /1GB -as [int]),($vdisk.Capacity /1GB -as [int]) 

         } 

         $result -join (", ") 

   foreach ($vm in (get-vm)) { 

     $props = @{'VMName'=$vm.Name; 

           'IP Address'= $vm.Guest.IPAddress[0]; #$VM.ExtensionData.Summary.Guest.IpAddress 

           'PowerState'= $vm.PowerState; 

           'Domain Name'= ($vm.ExtensionData.Guest.Hostname -split '\.')[1,2] -join '.';           

           'vCPU'= $vm.NumCpu; 

           'RAM(GB)'= $vm.MemoryGB; 

           'Total-HDD(GB)'= $vm.ProvisionedSpaceGB -as [int]; 

           'HDDs(GB)'= ($vm | get-harddisk | select-object -ExpandProperty CapacityGB) -join " + "           

           'Datastore'= (Get-Datastore -vm $vm) -split ", " -join ", "; 

           'Partition/Size' = Get-InternalHDD -VMName $vm.Name 

           'Real-OS'= $vm.guest.OSFullName; 

           'Setting-OS' = $VM.ExtensionData.summary.config.guestfullname; 

           'EsxiHost'= $vm.VMHost; 

           'vCenter Server' = ($vm).ExtensionData.Client.ServiceUrl.Split('/')[2].trimend(":443") 

           'Hardware Version'= $vm.Version; 

           'Folder'= $vm.folder; 

           'MacAddress' = ($vm | Get-NetworkAdapter).MacAddress -join ", "; 

           'VMX' = $vm.ExtensionData.config.files.VMpathname; 

           'VMDK' = ($vm | Get-HardDisk).filename -join ", "; 

           'VMTools Status' = $vm.ExtensionData.Guest.ToolsStatus; 

           'VMTools Version' = $vm.ExtensionData.Guest.ToolsVersion; 

           'VMTools Version Status' = $vm.ExtensionData.Guest.ToolsVersionStatus; 

           'VMTools Running Status' = $vm.ExtensionData.Guest.ToolsRunningStatus; 

           'SnapShots' = ($vm | get-snapshot).count; 

           'DataCenter' = $vm | Get-Datacenter; 

           'vNic' = Get-VNICinfo -VMName $vm.name; 

           'PortGroup' = ($vm | Get-NetworkAdapter).NetworkName -join ", "; 

           'RDMs' = Get-RDMDisk -VMName $VM.name 

           #'Department'= ($vm | Get-Annotation)[0].value; 

           #'Environment'= ($vm | Get-Annotation)[1].value; 

           #'Project'= ($vm | Get-Annotation)[2].value; 

           #'Role'= ($vm | Get-Annotation)[3].value; 

           } 

     $obj = New-Object -TypeName PSObject -Property $Props 

     Write-Output $obj | select-object -Property 'VMName', 'IP Address', 'Domain Name', 'Real-OS', 'vCPU', 'RAM(GB)', 'Total-HDD(GB)' ,'HDDs(GB)', 'Datastore',

'Partition/Size', 'Hardware Version', 'PowerState', 'Setting-OS', 'EsxiHost', 'vCenter Server', 'Folder', 'MacAddress', 'VMX', 'VMDK', 'VMTools Status', 'VMTools

Version', 'VMTools Version Status', 'VMTools Running Status', 'SnapShots', 'DataCenter', 'vNic', 'PortGroup', 'RDMs' , 'Folder' 

   } 

Get-VMinventory |export-csv c:\temp\vm-all-info.csv

2 Replies
kunaludapi
Expert
Expert

Check out this community thread and will be helpful

complete vminventory in a datacenter

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
esxi1979
Expert
Expert

Can you modify your script to include below

  1. $Scsilun = Get-ScsiLun 
  2. $Datastore = Get-Datastore 
  3. ForEach ($Datacenter in (Get-Datacenter)) { 
  4.     ForEach ($Cluster in ($Datacenter | Get-Cluster)) { 
  5.         ForEach ($VM in ($Cluster |  Get-VM)) { 
  6.             ForEach ($HardDisk in ($VM | Get-HardDisk)) { 
  7.                 $ds = Get-Datastore -Name $($HardDisk.FileName.Split("]")[0].TrimStart("[")) | Select -First 1 
  8.                 $dsLun = @() 
  9.                 $dsLunID = @() 
  10.                 $dsWwwn = @() 
  11.                 $Scsilun | Where-Object {$_.CanonicalName -match $ds.extensiondata.info.vmfs.Extent.DiskName} | % {  
  12.                     $dsLun += $_.CanonicalName         
  13.                     $dsLunID += $_.RunTimeName.Split(':')[-1].Trim('L'
  14.                     } 
  15.                 $esx = Get-VMHost -Name $vm.VMHost.Name 
  16.                 $lunKey = @() 
  17.                 $lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object {$dsLun -contains $_.CanonicalName} | % {$_.Key} 
  18.                 $lunWWN = @() 
  19.                 $lunWWN = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Where-Object {$lunKey -contains $_.Lun} | % {$_.Path | %{"{0:x}" -f $_.Transport.NodeWorldWideName}}      
  20. "" | Select-Object -Property @{N="VM";E={$VM.Name}}, 
  21.                     @{N="VMIP1";E={$vm.Guest.IPAddress[0]}}, 
  22.                     @{N="VMIP2";E={$vm.Guest.IPAddress[1]}}, 
  23.                     @{N="VMIP3";E={$vm.Guest.IPAddress[2]}},      
  24.                     @{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},      
  25.                     @{N="VM CPU Core#";E={$vm.NumCPU}}, 
  26.                     @{N="Datacenter";E={$Datacenter.name}}, 
  27.                     @{N="Cluster";E={$Cluster.Name}}, 
  28.                     @{N="Host";E={$vm.VMHost.Name}}, 
  29.                     @{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}}, 
  30.                     @{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}}, 
  31.                     @{N="Hard Disk";E={$HardDisk.Name}}, 
  32.                     @{N="Datastore";E={$ds.Name}}, 
  33.                     @{N="LUN";E={[string]::Join(',',$dsLun)}}, 
  34.                     @{N="LUNID";E={[string]::Join(',',$dsLunId)}}, 
  35.                     @{N="LUNWWN";E={[string]::Join(',',$lunWWN)}}, 
  36.                     @{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}}, 
  37.                     @{N="VMDKpath";E={$HardDisk.FileName}}, 
  38.                     @{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}}, 
  39.                     @{N="Drive Size";E={$HardDisk.CapacityGB}} 
  40.             } 
  41.         } 
  42.     } 

======================================================================================================================================================

ignore syntax

'Real-OS'= $vm.guest.OSFullName; 

           'Setting-OS' = $VM.ExtensionData.summary.config.guestfullname;

           'Domain Name'= ($vm.ExtensionData.Guest.Hostname -split '\.')[1,2] -join '.';           

      

           'RAM(GB)'= $vm.MemoryGB; 

            'Folder'= $vm.folder; 

           'MacAddress' = ($vm | Get-NetworkAdapter).MacAddress -join ", ";

           'VMTools Status' = $vm.ExtensionData.Guest.ToolsStatus; 

           'VMTools Version' = $vm.ExtensionData.Guest.ToolsVersion; 

           'VMTools Version Status' = $vm.ExtensionData.Guest.ToolsVersionStatus; 

           'VMTools Running Status' = $vm.ExtensionData.Guest.ToolsRunningStatus; 

             'SnapShots' = ($vm | get-snapshot).count; 

            

              $VMInfo.Powerstate = $vm.Powerstate

      $VMInfo.OS = $vm.Guest.OSFullName

      $VMInfo.Folder = ($vm | Get-Folderpath).Path

    $vms.CPUAffinity = $vm.Config.CpuAffinity

$vms.CPUHotAdd = $vm.Config.CpuHotAddEnabled

$vms.CPUShare = $vm.Config.CpuAllocation.Shares.Level

$vms.TimeSync = $vm.Config.Tools.SyncTimeWithHost

$vms.HardwareVersion = $vm.config.Version

    $vms.MemoryLimit = $vm.resourceconfig.memoryallocation.limit

    $vms.MemoryReservation = $vm.resourceconfig.memoryallocation.reservation

    $vms.CPUreservation = $vm.resourceconfig.cpuallocation.reservation

    $vms.CPUlimit = $vm.resourceconfig.cpuallocation.limit

$vms.CBT = $vm.Config.ChangeTrackingEnabled

$vms.Swapped = $vm.Summary.QuickStats.SwappedMemory

$vms.Ballooned = $vm.Summary.QuickStats.BalloonedMemory

$vms.Compressed = $vm.Summary.QuickStats.CompressedMemory

$PortGroup = @($PortGroups | Where-Object {$_.name -eq $dev.DeviceInfo.summary})[0]

$Report.vmCreatedByUser = $VM.CustomFields["CreatedBy"] 

        $Report.vmCreatedDate = $VM.CustomFields["CreatedOn"] 

        $Report.VLANid = [string]::Join(',',(Get-VirtualPortgroup -VM $vm | %{$_.VlanId})) 

Reply
0 Kudos