2 Replies Latest reply on Aug 14, 2019 2:38 AM by lmoglie

    Power shell script to retrieve information on VM

    bpbhai Lurker

      Hi , I would like to create a report in which i would like to retrieve information about VM's from a Data Center , the information on VM should contain

       

      1. The Operating system 

      2. Name of VM

      3. VM host

      4. Ip address

      5. Mac address

       

      and if possible custom attributes

       

      can some one help me here:  i already tried this script but somehow for some machines OS info is not coming and hence report is not getting published , also i have not included custom attributes in this script

       

      $VCServerName = "..................."

      $VC = Connect-VIServer $VCServerName

       

       

      $datacenter= "datacenter name"

      $ExportFilePath = "D:\Export-VMInfo.csv"

       

      $Report = @()

      $VMs = Get-Datacenter $datacenter | Get-VM

       

       

       

      ForEach ($VM in $VMs) {

            $VMView = $VM | Get-View

        write-host $VMView

            $VMInfo = {} | Select VMName,OS,IPAddress,Host

            $VMInfo.VMName = $vm.name

           

            $VMInfo.OS = $vm.Guest.OSFullName

          

            $VMInfo.IPAddress = $vm.Guest.IPAddress[0]

        

            $VMInfo.Host = $vm.host.name

           

            $Report += $VMInfo

       

      }

      $Report = $Report | Sort-Object VMName