Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

Getting too many results

$
0
0

I am trying to write a script to get all the vms in a set of clusters and the datastores they are on with the amount of datastore freespace. For some reason it is getting ALL the vms on the datastores.

 

 

 

$ServerName = "servername"
$report = @()
$cl_filter_pattern = "*PCI"
$digits = 2
Connect-VIServer $ServerName
foreach($cluster in Get-Cluster | where {$_.name -like $cl_filter_pattern}){
    Get-VMHost -Location $cluster | Get-Datastore | %{
        $vms = $cluster | Get-VM
foreach ($vm in $vms){
$info = "" | select DataCenter, Cluster, Datastore, VM, Capacity, Provisioned, Available, PercFree
             $info.Datacenter = $_.Datacenter
             $info.Cluster = $cluster.Name
             $info.Datastore = $_.Name
$info.VM = $vm.Name
             $info.Capacity = [math]::Round($_.capacityMB/1024,2)
             $info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)
             $info.Available = [math]::Round($info.Capacity - $info.Provisioned,2)
$info.PercFree = [math]::Round(100*$_.FreeSpaceMB/$_.CapacityMB,$digits)
             $report += $info
}
    }
}
$report | Export-Csv "C:\datastore-vms.csv" -NoTypeInformation -UseCulture
Disconnect-VIServer $ServerName -Confirm:$false

 

Where am I going wrong?


Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>