Last active
June 5, 2023 08:01
-
-
Save mikolatero/75e2fd948a8d547233fbf70100c74abf to your computer and use it in GitHub Desktop.
Get CSV report from VMware vCenter with Name, Total size of folder, Size of disk, CPU and RAM from all VM's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$date = Get-Date -uformat "%Y-%m-%d_%H-%M-%S" | |
$csvname = "report-$date" | |
$path = "C:\vCenter-Reports\" | |
$vcenterip = "A.B.C.D" | |
$folder = "Datacenters" | |
If(!(test-path $path)) | |
{ | |
New-Item -ItemType Directory -Force -Path $path | |
} | |
Connect-VIServer -server $vcenterip | |
$report = @() | |
foreach ($vm in Get-Folder $folder | Get-VM){ | |
$view = Get-View $vm | |
$datastore = Get-VM -Name $vm.Name | select @{N='Datastore';E={(Get-View -Id $_.DatastoreIdList -Property Name).Name -join ','}} | |
$row = '' | select Name, CPU, RAM, Provisioned, Total, Datastore | |
$row.Name = $vm.Name | |
$row.CPU = $vm.NumCpu | |
$row.RAM = $vm.MemoryGB | |
$row.Provisioned = [math]::round($vm.ProvisionedSpaceGB , 2) | |
$row.Total = [math]::round(($view.config.hardware.Device | Measure-Object CapacityInKB -Sum).sum/1048576 , 2) | |
$row.Datastore = $datastore.Datastore | |
$report += $row | |
} | |
$report | Sort Name | Export-Csv -Path "$path\$csvname.csv" -delimiter ";" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment