I am using below script that gives me below output, need help to add additional column that will show the size of the each virtual hard disks.
PowerState | ProvisionedSpaceGB | Device | RDM | Datastore | Type | MountPoint | Filer | CanonicalName | Model | Vendor | CapacityGB |
$report = @()
ForEach ($vc in $global:DefaultVIServers) {
Write-Host -ForeGroundColor Yellow "[ $((Get-Date).ToString()) ]# Evaluating VMs on vCenter $($vc.Name)"
$clusters = Get-View -ViewType ClusterComputeResource -Server $vc.Name -Property Name, Parent
$esxihosts = Get-View -ViewType HostSystem -Server $vc.Name -Property Name, Parent, Config.StorageDevice.ScsiLun
$datastores = Get-View -ViewType Datastore -Server $vc.Name -Property name, Info, Parent
$vms = Get-View -ViewType VirtualMachine -Server $vc.Name -Property name,runtime, Summary.Storage, config.Hardware.Device
ForEach ($vm in $vms) {
$esxi = $esxihosts|? {$_.MorEf -eq $vm.Runtime.Host}
$vdisks = $vm.config.hardware.device|? {$_.CapacityInKB}
ForEach ($vdisk in $vdisks) {
$dsInfo = ($datastores|? {$_.MorEf -eq $vdisk.backing.datastore})
if ($dsInfo.Info.Nas) {
$rdm = "False"
if ($dsInfo.Info.Nas.RemotePath -match "vol") {
$vendor = "A"
}
ElseIf ($dsInfo.Info.Nas.RemotePath -match "export") {
$vendor = "B"
}
Else {
$vendor = "C"
}
$dsType = $dsInfo.Info.Nas.Type
$mountPoint = $dsInfo.Info.Nas.RemotePath
$filer = $dsInfo.Info.Nas.RemoteHost
$lunInfo = @{"CanonicalName" = "N/A";Model="N/A";Vendor="$($vendor)"}
$capacity = [math]::round($dsInfo.Info.nas.Capacity/1GB,2)
}
Else {
$dsType = $dsInfo.Info.VMFS.Type
$mountPoint = "N/A"
$filer = "N/A"
if ($vdisk.Backing.CompatibilityMode) {
$rdm = "True"
$lunInfo = $esxi.config.storagedevice.scsiLun |? {$_.Uuid -eq $vdisk.Backing.LunUuid}
$capacity = [math]::round(($lunInfo.Capacity.BlockSize * $lunInfo.Capacity.Block)/1GB,2)
}
Else {
$rdm = "False"
$lunInfo = $esxi.config.storagedevice.scsiLun |? {$_.CanonicalName -eq $dsInfo.Info.VMFS.Extent.DiskName}
$capacity = [math]::round(($lunInfo.Capacity.BlockSize * $lunInfo.Capacity.Block)/1GB,2)
}
}
$obj = ""|Select vCenter, Cluster, Host, Name, PowerState, ProvisionedSpaceGB, Device, RDM, Datastore, Type, MountPoint, Filer, CanonicalName, Model, Vendor, CapacityGB
$obj.vCenter = $vc.Name
$obj.Cluster = ($clusters|? {$_.MorEf -eq $esxi.Parent}).Name
$obj.Host = $esxi.name
$obj.Name = $vm.Name
$obj.PowerState = $vm.Runtime.PowerState
$obj.ProvisionedSpaceGB = [math]::Round(($vm.Summary.Storage.Committed + $vm.Summary.Storage.UnCommitted)/1GB,2)
$obj.Device = $vdisk.DeviceInfo.Label
$obj.RDM = $rdm
$obj.Datastore = $dsInfo.name
$obj.Type = $dsType
$obj.MountPoint = $mountPoint
$obj.Filer = $filer
$obj.CanonicalName = $lunInfo.CanonicalName
$obj.Model = $lunInfo.Model
$obj.Vendor = $lunInfo.Vendor
$obj.CapacityGB = $capacity
$report += $obj
}
}
}$report|Export-csv VirtualMachine_Report.csv -NoTypeInformation
Any input will be highly appreciated.
Isn't that what the CapacityGB property is doing?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
its showing the capacity of the LUN.
Got it, try the attached version.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference