更多vsphere自动化运维视频课程


##########统计虚拟机名称、虚拟机所在文件夹、虚拟机所在存储lun、存储lun的已用容量信息、存储LUN已用百分比##########

$results = @()

$resultslun = @()

$vms = Get-VM

foreach ($vm in $vms) {

      $datastores = Get-Datastore -VM $vm

   foreach ($datastore in $datastores) {

$datastoreUsedStorage = [math]::Round(($datastore.CapacityGB - $datastore.FreeSpaceGB), 2)

       $result = [PSCustomObject]@{

           "虚拟机" = $vm.Name

           "应用系统" = $vm.Folder

           "存储LUN" = $datastore.Name

       }

       $results += $result

   }

}

$dass = Get-Datastore

foreach ($das in $dass) {

$totalCapacityGB = [math]::Round(($das.CapacityGB), 2)  

$datastoreUsedStorage = [math]::Round(($das.CapacityGB - $das.FreeSpaceGB), 2)

$usagePercentage = [math]::Round(($datastoreUsedStorage / $totalCapacityGB) * 100, 2)

$resultl = [PSCustomObject]@{

"存储LUN" = $das.Name

"存储LUN容量(GB)" = $das.CapacityGB

"存储LUN已用空间(GB)" = "$datastoreUsedStorage"

"存储LUN使用率(%)" = $usagePercentage

       }

$resultslun += $resultl

   }

#统计虚拟机名称、虚拟机存储位置、虚拟机所属系统名称

$results | Export-Csv  c:\yili\cwbn-061201.csv -Encoding UTF8  -NoTypeInformation

#统计存储名称、存储容量、存储已用空间、存储使用率

$resultslun | Export-Csv  c:\yili\cwbl-061201.csv -Encoding UTF8  -NoTypeInformation


更多vsphere自动化运维视频课程