5 Replies Latest reply on Jan 4, 2013 5:25 AM by Grzesiekk

    help power shell VM info

    ironman13 Novice

      Hi,

       

      I need help with my shell script that dates me the name of the vm, the cpu, memory and host.
      I go back all except the host, I have the following errreur.

       

       

      « Item » : « Exception de HRESULT : 0x800A03EC »
      Au niveau de C:\temp\ESXtest.ps1 : 29 Caractère : 18
      + $Sheet.Cells.Item <<<< ($intRow,7) = $objItem.Host
          + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
          + FullyQualifiedErrorId : CatchFromBaseAdapterParameterizedPropertySetValueTI

       

       

      the script

       

       

      Connect-VIServer -Server iron -User stats -Password 123

       

      $Excel = New-Object -Com Excel.Application
      $Excel.visible = $True
      $Excel = $Excel.Workbooks.Add()
      $Addsheet = $Excel.sheets.Add()
      $Sheet = $Excel.WorkSheets.Item(1)
      $Sheet.Cells.Item(1,1) = "Name"
      $Sheet.Cells.Item(1,2) = "NB CPU"
      $Sheet.Cells.Item(1,3) = "Memory (MB)"
      $Sheet.Cells.Item(1,4) = "ProvisionedSpaceGB"
      $Sheet.Cells.Item(1,5) = "Notes"
      $Sheet.Cells.Item(1,7) = "VMHost"

       

      $WorkBook = $Sheet.UsedRange
      $WorkBook.Font.Bold = $True
      $WorkBook.EntireColumn.AutoFit()
      $intRow = 2

       

      $colItems = Get-VM | Select-Object "Name", "NumCPU", "MemoryMB", "ProvisionedSpaceGB", "Notes", "Host"
      foreach ($objItem in $colItems)
      {
      $Sheet.Cells.Item($intRow,1) = $objItem.Name
      $Sheet.Cells.Item($intRow,2) = $objItem."NumCPU"
      $Sheet.Cells.Item($intRow,3) = $objItem."MemoryMB"
      $Sheet.Cells.Item($intRow,4) = $objItem."ProvisionedSpaceGB"
      $Sheet.Cells.Item($intRow,5) = $objItem."Notes"
      $Sheet.Cells.Item($intRow,7) = $objItem.Host
      #foreach ($objItem in $colItems)

       

      $intRow = $intRow + 1
      }

       

      # $powerstate = $objItem.PowerState
      # If ($PowerState -eq 1) {$power = "Powerd On"}
      # Else {$power = ?Powerd Off?}

       


      Disconnect-VIServer -Confirm:$false