Hi All
I trying to create script to get the vm disk usage - used space - free space and total disk space .
I have used this script which helps me getting the required result .
but I need to modify the script for each cluster it should get the vms in that cluster and check the vm disuage . and export to csv file
$vms = Import-CSV "C:\Cluster.csv
$outputfile = "c:\Diskusage.csv"
Connect-viserver VC -user vcadmin -password
foreach ($vm in $vms){
Get-VM $vm.name | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskCapacityGB";Expression={[math]::Round((($_.Capacity)/1GB),2)}},@{Name="DiskUsedMB";Expression={[math]::Round((($_.Capacity - $_.FreeSpace)/1MB),2)}},@{Name="DiskFreeMB";Expression={[math]::Round((($_.FreeSpace)/1MB),2)}} | Export-Csv -NoTypeInformation $outputfile }
Disconnect-viserver
Attached the output file
Kinldy help me in creating the script
Can you try like this ?
Connect-viserver VC -user vcadmin -password foreach($cluster in Get-CLuster){ $outputfile = "c:\" + $cluster.Name + "-Diskusage.csv"
Get-VM -Location $cluster | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskCapacityGB";Expression={[math]::Round((($_.Capacity)/1GB),2)}}, @{Name="DiskUsedMB";Expression={[math]::Round((($_.Capacity - $_.FreeSpace)/1MB),2)}}, @{Name="DiskFreeMB";Expression={[math]::Round((($_.FreeSpace)/1MB),2)}} | Export-Csv -NoTypeInformation $outputfile
} Disconnect-viserver
The script will create a seperate CSV file for each cluster.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can you try like this ?
Connect-viserver VC -user vcadmin -password foreach($cluster in Get-CLuster){ $outputfile = "c:\" + $cluster.Name + "-Diskusage.csv"
Get-VM -Location $cluster | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskCapacityGB";Expression={[math]::Round((($_.Capacity)/1GB),2)}}, @{Name="DiskUsedMB";Expression={[math]::Round((($_.Capacity - $_.FreeSpace)/1MB),2)}}, @{Name="DiskFreeMB";Expression={[math]::Round((($_.FreeSpace)/1MB),2)}} | Export-Csv -NoTypeInformation $outputfile
} Disconnect-viserver
The script will create a seperate CSV file for each cluster.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi lucd
This Script works fine .
I need to input the Cluster parameters using import-csv from a csv file .
For Eg: sample.csv
ClusterName
Cluster1
Cluster2
Can u also help me with this
Thanks for the valuable inputs .
No, problem, try this version
Connect-viserver VC -user vcadmin -password
foreach($cluster in (Get-Cluster -Name (Import-Csv "C:\sample.csv" | %{$_.ClusterName}))){ $outputfile = "c:\" + $cluster.Name + "-Diskusage.csv"
Get-VM -Location $cluster | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskCapacityGB";Expression={[math]::Round((($_.Capacity)/1GB),2)}}, @{Name="DiskUsedMB";Expression={[math]::Round((($_.Capacity - $_.FreeSpace)/1MB),2)}}, @{Name="DiskFreeMB";Expression={[math]::Round((($_.FreeSpace)/1MB),2)}} | Export-Csv -NoTypeInformation $outputfile
} Disconnect-viserver
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Simplest method is use a FREE tool:
Works with vSphere 5 also.. you can export everything, hosts, VM's, disks, networks, even snapshot usage.. It's very nice, I would check it out.
Hi All
Thanks to LUCD
I was able to import from csv and im getting the desired output .
I modified the script as LUCD Advice .
$clusters = Import-csv "C:\Scripts\Cluster.csv
Connect-viserver vcserver -user vcadmin -password
foreach ($cluster in $clusters){
$outputfile = "c:\scripts\"+ $cluster.Name + "-Diskusage.csv"
Get-cluster $cluster.name |
Get-VM |
Where { $_.PowerState -eq "PoweredOn" } |
Get-VMGuest | where { $_.State -eq "Running" } |
Select VMName -ExpandProperty Disks |
Select VMName, Path,
@{Name="DiskCapacityGB";Expression={[math]::Round((($_.Capacity)/1GB),2)}},
@{Name="DiskUsedGB";Expression={[math]::Round((($_.Capacity - $_.FreeSpace)/1GB),2)}},
@{Name="DiskFreeGB";Expression={[math]::Round((($_.FreeSpace)/1GB),2)}} |
Export-Csv -NoTypeInformation $outputfile
}
Disconnect-viserver vcserver -confirm:$false
Hi ,
Even Am also looking to find the disk space in the below mentioned format.
VmName | Path | DiskCapacityGB | DiskUsedMB | DiskFreeMB |
VCENTER5 | C:\ | 19.43 | 15940.6 | 3958.39 |
VCENTER5 | E:\ | 20.47 | 999.21 | 19958.79 |
COEVSDVC | C:\ | 39.9 | 36159.69 | 4698.3 |
COEVSDVC | F:\ | 40 | 876.67 | 40080.32 |
COEVSDDC | C:\ | 39.9 | 12865.68 | 27992.32 |
Could you help me with any script , also let me know where should i run the script.
Am sorry, Am new to VMware.
I think the script just above you question does exactly that.
And for running PowerCLI scripts have a look at Execute PowerCLi scripts out of PowerCli Console?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I was wandering what is the difference between $VM.HardDisks.CapacityGB and $VM.ProvisionedSpaceGB.
my VM is provisioned (Thin) with One Disk size 32Gb (No SnapShots) which is exactly tha value shown in $VM.HardDisks.CapacityGB.
the value of $VM.ProvisionedSpaceGB shows 42 Gb. (shown only in VI client).
datastore browser shows this,
there are No other significant files (large) in the VM folder. VM is powered off.
can you explain the difference between the 2 properties ?
Thanks, Avi
There could be a number of reasons for this.
Have a look with the Datastore Browser from the vSphere client in the VM's folder, are there perhaps any hidden snapshot files in there ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference