2 Replies Latest reply on Nov 21, 2013 11:39 AM by SteveR77

    Array initalization?

    SteveR77 Novice

      I am working with the following reporting PowerCli script and I am a bit confused as to why the value for the CPUType variable is posting an error about a Null Array.

       

      Thanks for your assistance.

       

       

      Get-PowerCLIConfiguration

      Set-PowerCLIConfiguration -ProxyPolicy Noproxy

      #Connect to MyVCenter

      Connect-VIServer  my vCenter -User joeuser  -Password ******************************


       


      $ExportFilePath = "C:\temp\Export-VMInfo.csv"


      $Report =@()


      #Get List of VM's

      $TDCVMs = Get-VM -Location "TDC"


      $i=0


      foreach ($VM in $TDCVMs) {


      $i++


      $VMView = $VM | Get-View

      $VMInfo = {} | Select VMName,Host,Cluster,Datastore,CPUType,NumCPU,Powerstate,OS,Snapshot,IPAddress,ToolsStatus,MemMb,NumHardDisks,HardDisk,DiskGb,DiskFree,DiskUsed,Notes      


      $VMInfo.VMName = $vm.name

      $VMInfo.Powerstate = $vm.Powerstate

      $VMInfo.OS = $vm.Guest.OSFullName

      $VMInfo.Snapshot = Get-Snapshot $VM

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

      $VMInfo.ToolsStatus = $VMView.Guest.ToolsStatus

      $VMInfo.Host = Get-VMHost -VM $VM

      $VMInfo.Cluster = Get-Cluster -VM $VM

      $VMInfo.Datastore = Get-Datastore -VM $VM

      $VMInfo.CPUType = $vm.Hardware.CpuPkg[0].Description  <---  What is off here??  

      $VMInfo.NumCPU = $vm.NumCPU

      $VMInfo.MemMb = [Math]::Round(($vm.MemoryMB),2)

      $VMInfo.NumHardDisks = $vm.Guest.Disks.count

      $VMInfo.HardDisk = Get-HardDisk -VM $VM

      $VMInfo.DiskGb = [Math]::Round(((Get-HardDisk -VM $VM | Measure-Object -Property CapacityKB -Sum).Sum * 1KB / 1GB),2)

      $VMInfo.DiskFree = [Math]::Round((($vm.Guest.Disks | Measure-Object -Property FreeSpace -Sum).Sum / 1GB),2)

      $VMInfo.DiskUsed = $VMInfo.DiskGb - $VMInfo.DiskFree

      $VMInfo.Notes =$vm.notes


      Write-Progress -activity "Building Inventory Report" -status "Status: "-PercentComplete(($i/$TDCVMs.count)*100)


      $Report += $VMInfo


      }


      $Report = $Report | Sort-Object VMName


      IF ($Report -ne "") {


      $report | Export-Csv $ExportFilePath -NoTypeInformation


      }