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
Found the answer in another post
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
}
It gets better and I may close this discussion.
Just running a Get-VM gives you duplicates
Found the answer in another post