VMware Cloud Community
vin01
Expert
Expert
Jump to solution

Complete VM information

Hi

I'm pretty new to get-view with the help of the old threads form the Master LucD I written the below Code but i need to add few more information in the code .

LucD can you please help me out.

Information need to fetch :

Lun NAA of each hardisk in output

Lun ID of that NAA

VMConfigFile

VMDKpath for each harddisk

Size of that .vmdk

-------------------------------------

Some thing went wrong in the code unable to get below information

IP address (Some vms contains multiple IPs )

network adapter (like.. network adapter 1 etc..)

need port group information for DVS b/c some vms are on DVS

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

foreach($vm in (Get-View -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)){

   # $t = Get-View $vm.Parent -Property Name,Parent

    #$path = $t.Name

    #while($t.GetType().Name -eq "Folder"){

     #   $t = Get-View $t.Parent

      #  if($t.Name -ne "vm"){

       #     $path = $t.Name + "/" + $path

        #}

    #}

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

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

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

    }

        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

    }

    $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={$add=($vm.Guest.Net | %{$_.IpAddress})}.(([string]::Join(',',$add)))},

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

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

    @{N='VMHost';E={(Get-View -Id $vm.Runtime.Host).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={($_.DeviceInfo.Label).BusNumber}},

    @{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="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*")}).name}},

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

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

}

Sample Output :

output.JPG

Regards Vineeth.K
Reply
0 Kudos
24 Replies
veera1987
Contributor
Contributor
Jump to solution

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!!!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
veera1987
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

May I suggest to open a new thread.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
veera1987
Contributor
Contributor
Jump to solution

Hi LuCD,

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

Reply
0 Kudos