October 13, 2018

Get Virtual Machines provisioned Disk size for a list of VMs




Below is a script to get VM provisioned Disk size from list of VMs in a .txt file

you will be getting Total provisioned Disk size for each VM in the list and output will be save to a CSV file 


#Get Virtual Machines Disk size for a list
$vmList = Get-Content D:\temp\inputFile.txt
$results= foreach ($vmName in $vmList) {Get-VM $vmName | Select-Object Name,@{n="HardDiskSizeGB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}}
$results | Export-Csv "D:\temp\file.csv" 



Redirecting to a CSV file
| Export-Csv "D:\temp\file.csv


Invoke lines from a text file to Power CLI
$vmList = Get-Content D:\temp\inputFile.txt
 

No comments:

Post a Comment