jamesreinke2
Enthusiast
Enthusiast

PowerCli running through 2x

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
jamesreinke2
Enthusiast
Enthusiast
0 Kudos
3 Replies
jamesreinke2
Enthusiast
Enthusiast

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

}

0 Kudos
jamesreinke2
Enthusiast
Enthusiast

It gets better and I may close this discussion.

Just running a Get-VM gives you duplicates

0 Kudos
jamesreinke2
Enthusiast
Enthusiast

Found the answer in another post

Get-VMHost returns duplicate host names

0 Kudos