VMware vSphere

 View Only
  • 1.  Power shell script to retrieve information on VM

    Posted Aug 13, 2019 02:39 PM

    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



  • 2.  RE: Power shell script to retrieve information on VM

    Posted Aug 13, 2019 03:23 PM


  • 3.  RE: Power shell script to retrieve information on VM

    Posted Aug 14, 2019 09:39 AM

    Hi,

    something like this??

    Connect-VIServer -Server <VCSA> -User <Userrname> -Password <Password>

    $DTC = "<Datacenter>"

    $Report = @()

    ForEach ($VM in (Get-Datacenter $DTC) | Get-VM) {

    $tempvm=@{}

    $tempvm.Name = $VM.Name

    $tempvm.GuestOS = If (!$VM.Guest.OSFullName) {"Tools Not Running\Unknown"} Else {$VM.Guest.OSFullName}

    $tempvm.IP = If (!$VM.Guest.IPAddress[0]) {"Tools Not Running\Unknown"} Else {$VM.Guest.IPAddress[0]}

    $tempvm.FullName = If (!$VM.Guest.hostname) {"Tools Not Running\Unknown"} Else {$VM.Guest.hostname}

    $tempvm.MacAddress = (Get-NetworkAdapter -VM $VM.Name).MacAddress

    #$tempvm.CustomFields = $VM.CustomFields  # Custom Attributes

      $temp = New-Object -TypeName PSObject -Property $tempvm

    $Report += $temp

    }

    $Report | Select Name, GuestOS, IP, FullName, MacAddress |  Sort Name | export-csv ".\Export-VMInfo.csv"

    Best Regards

    Lorenzo Moglie



  • 4.  RE: Power shell script to retrieve information on VM

    Posted Aug 20, 2019 09:07 AM

    Thanks for this bout it's not printing the OS of the VM which are switched off, as I have to get all the machines which have windows 7 as their OS, this information is not coming

    I tried with this but it's not working , maybe I am doing some mistake.

    $tempvm.ConfigGuestOS = $VM.Config.GuestFullName



  • 5.  RE: Power shell script to retrieve information on VM

    Posted Aug 20, 2019 10:27 AM

    Hi,

    Why don't you use RVTools instead? (https://www.robware.net/rvtools/ )

    It's easier if you only want a report.