VMware Cloud Community
jamesreinke2
Enthusiast
Enthusiast
Jump to solution

PowerCli running through 2x

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

Reply
0 Kudos
1 Solution

Accepted Solutions
jamesreinke2
Enthusiast
Enthusiast
Jump to solution

Reply
0 Kudos
3 Replies
jamesreinke2
Enthusiast
Enthusiast
Jump to solution

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

}

Reply
0 Kudos
jamesreinke2
Enthusiast
Enthusiast
Jump to solution

It gets better and I may close this discussion.

Just running a Get-VM gives you duplicates

Reply
0 Kudos
jamesreinke2
Enthusiast
Enthusiast
Jump to solution

Found the answer in another post

Get-VMHost returns duplicate host names

Reply
0 Kudos