VMware vSphere

 View Only
  • 1.  PowerCli running through 2x

    Posted Oct 05, 2018 03:04 PM

    Hi all, This scripts output duplicates all the VMs. I dont know why except it started since VCSA 6.5 U2 was installed. The script below as you can see just pulls the names of the VMs to get the information needed. Is this the way to go or can anyone tell me what changed?

    Get-VM | Sort -Property Name | Select Name, PowerState, Folder, NumCpu, MemoryGB, UsedSpaceGB, ProvisionedSpaceGB, @{n="HardDiskSizeGB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}, @{Label="NumSnapshots";Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}}, @{Label="TotalSnapShotSizeMB";Expression={(Get-Snapshot -VM $_ | Measure-Object -Sum SizeMB).Sum}} | Export-Csv -Path $file -NoClobber

    Thanks in advance



  • 2.  RE: PowerCli running through 2x

    Posted Oct 05, 2018 03:20 PM

    Just created this for loop. Same thing on the output

    $file = "c:\temp\myVMInfo4.csv"

    if (Test-Path $file) {

      Remove-Item $file

    }

    $vms = Get-VM | sort -Property Name

    foreach ($vm in $vms) {

      $name = $vm.Name

      $power = $vm.PowerState

      $folder = $vm.Folder

      $cpus = $vm.NumCpu

      $memory = $vm.MemoryGB

      $usedSpace = $vm.UsedSpaceGB

      $totalSpace = $vm.ProvisionedSpaceGB

      $hardDiskSize = (Get-HardDisk -VM $name | Measure-Object -Sum CapacityGB).Sum

      $snapShots = (Get-Snapshot -VM $name | Measure-Object).Count

      $snapShotSize = (Get-Snapshot -VM $name | Measure-Object -Sum SizeMB).Sum

      $vmStats = "$name,$power,$folder,$cpus,$memory,$usedSpace,$totalSpace,$hardDiskSize,$snapShots,$snapShotSize"

      Add-Content -Value $vmStats -Path $file

    }



  • 3.  RE: PowerCli running through 2x

    Posted Oct 05, 2018 03:37 PM

    It gets better and I may close this discussion.

    Just running a Get-VM gives you duplicates



  • 4.  RE: PowerCli running through 2x
    Best Answer

    Posted Oct 05, 2018 03:43 PM

    Found the answer in another post

    Get-VMHost returns duplicate host names