7 Replies Latest reply on Feb 6, 2019 12:22 PM by bkieca1972

    Powercli script question for exporting Data

    bkieca1972 Novice

      I am trying to export data from my 6.5 vcenter with the embedded database. I keep getting an error. This works in my 6.0 vcenter with no issues. Script is below the error messages

       

      Any assistance would be very much appreciated.

       

      ERRORS

       

      Cannot find an overload for
      "Round" and the argument count: "2".

      At
      C:\Users\wkieca\Desktop\Docs\2019-Trueup\Scripts\Inventory-spvcenter11.ps1:40
      char:5

      +   
      $VMInfo.DatastoreFree = [Math]::Round($ds.FreeSpaceGB,2)

      +   
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          +
      CategoryInfo          :
      NotSpecified: (:) [], MethodException

          +
      FullyQualifiedErrorId : MethodCountCouldNotFindBest

       

      Method invocation failed because
      [System.Object[]] does not contain a method named 'op_Subtraction'.

      At
      C:\Users\wkieca\Desktop\Docs\2019-Trueup\Scripts\Inventory-spvcenter11.ps1:41
      char:5

      +   
      $VMInfo.DatastoreUsed = [Math]::Round($ds.CapacityGb - $ds.FreeSp ...

      +   
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          +
      CategoryInfo          :
      InvalidOperation: (op_Subtraction:String) [], RuntimeException

          +
      FullyQualifiedErrorId : MethodNotFound

       

      Cannot find an overload for
      "Round" and the argument count: "2".

      At C:\Users\wkieca\Desktop\Docs\2019-Trueup\Scripts\Inventory-spvcenter11.ps1:40
      char:5

      +   
      $VMInfo.DatastoreFree = [Math]::Round($ds.FreeSpaceGB,2)

      +   
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          +
      CategoryInfo          :
      NotSpecified: (:) [], MethodException

          +
      FullyQualifiedErrorId : MethodCountCouldNotFindBest

       

      Method invocation failed because
      [System.Object[]] does not contain a method named 'op_Subtraction'.

      At
      C:\Users\wkieca\Desktop\Docs\2019-Trueup\Scripts\Inventory-spvcenter11.ps1:41
      char:5

      +   
      $VMInfo.DatastoreUsed = [Math]::Round($ds.CapacityGb - $ds.FreeSp ...

      +   
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          +
      CategoryInfo          :
      InvalidOperation: (op_Subtraction:String) [], RuntimeException

          + FullyQualifiedErrorId
      : MethodNotFound

       

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

       

      filter Get-FolderPath
      {

          $_ | Get-View | % {

            
      $row = "" | select Name, Path

            
      $row.Name
      = $_.Name

            
      $current =
      Get-View $_.Parent

            
      # $path = $_.Name # Uncomment out this line if
      you do want the VM Name to appear at the end of the path

            
      $path = ""

            
      do {

                
      $parent =
      $current

                
      if($parent.Name -ne "vm"){$path
      = $parent.Name + "\" +
      $path}

                
      $current =
      Get-View $current.Parent

            
      } while ($current.Parent -ne $null)

            
      $row.Path
      = $path

            
      $row

          }

      }

       

      $VCServerName =
      "spvcenter11.reyesholdings.com"

      $VC =
      Connect-VIServer $VCServerName
      -user RH\x-bkieca
      -password

      $VMFolder =
      "RFS"

      $ExportFilePath =
      "C:\Users\wkieca\Desktop\Docs\2019-Trueup\Export-spvcenter11.csv"

      $Report =
      @()

      $VMs =
      Get-VM

      $Datastores =
      Get-Datastore

      $VMHosts =
      Get-VMHost |
      select Name, Parent

      ForEach ($VM
      in $VMs)
      {

          $VMView = $VM | Get-View

          $ds = $Datastores | where {$_.ID -match ($vmview.Datastore
      | Select -First 1).Value}

          $VMInfo = {} | Select VMName,Powerstate,OS,Folder,IPAddress,ToolsStatus,ToolsVersion,Host,Cluster,Datastore,DatastoreFree,DatastoreUsed,NumCPU,MemMb,DiskGb, DiskFree, DiskUsed, BusinessUnit

          $VMInfo.VMName = $vm.name

          $VMInfo.Powerstate
      = $vm.Powerstate

          $VMInfo.OS = $vm.Guest.OSFullName

          $VMInfo.Folder = ($vm | Get-Folderpath).Path

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

          $VMInfo.ToolsStatus
      = $VMView.Guest.ToolsStatus

          $VMInfo.ToolsVersion
      = $VMView.Guest.ToolsVersion

          $VMInfo.Host = $vm.VMHost.Name

          $VMInfo.Cluster
      = $vm.VMhost.Parent.Name

          $VMInfo.Datastore
      = $ds.Name

          $VMInfo.DatastoreFree
      = [Math]::Round($ds.FreeSpaceGB,2)

          $VMInfo.DatastoreUsed
      = [Math]::Round($ds.CapacityGb - $ds.FreeSpaceGB,2)

          $VMInfo.NumCPU = $vm.NumCPU

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

          $VMInfo.DiskGb = [Math]::Round((($vm.Guest.Disks | Measure-Object -Property
      CapacityGB -Sum).Sum),2)

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

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

          $VMInfo.BusinessUnit
      = $vm.CustomFields.Item("Business Unit")

          $Report += $VMInfo

      }

      $Report =
      $Report |
      Sort-Object VMName

      IF ($Report
      -ne "")
      {

          $report | Export-Csv $ExportFilePath
      -NoTypeInformation

      }

      $VC =
      Disconnect-VIServer -Confirm:$False