Automation

 View Only
  • 1.  Total Storage amount in datacenter

    Posted May 23, 2013 08:44 PM

    I'm trying to get a script that will give me the total amount of space used in an entire data center. I will like to run it against the data center from the virtual centers. There are a total of about 1900 virtual machines and the VM's are spread across multiple LUNS. I need to get the overall figure for a migration.

    PS:  I will like to get the figures in GB instead of Megabytes and I also want it to spit out a report in .csv to my local machine (c:\scripts\xxxx.csv)



    Thanks guys.



  • 2.  RE: Total Storage amount in datacenter

    Posted May 23, 2013 10:38 PM

    You could try something like this

    Get-Datacenter | Select Name,
    @{N="Storage Used (GB)";E={
     
    $sum = Get-Datastore -Location $_ |
     
    where {$_.ExtensionData.Summary.MultipleHostAccess -and $_.Type -eq "VMFS"} |
     
    Measure-Object -Property CapacityGB,FreeSpaceGB -Sum
      [
    Math]::Round($sum[0].Sum - $sum[1].Sum,2)
    }}

    It will only take shared VMFS datastores into account.

    If you use other datastore types you can change the Where-clause



  • 3.  RE: Total Storage amount in datacenter

    Posted May 24, 2013 03:44 PM

    Thanks LucD. I will like to have it spit out a report in .csv format so that I can exprt it into Excel for my report. The path will be c:/scrpits/xxxxx.csv



  • 4.  RE: Total Storage amount in datacenter

    Posted May 24, 2013 05:14 PM

    Just pipe the results to the Export-Csv cmdlet.

    Something like this

    Get-Datacenter | Select Name,
    @{N="Storage Used (GB)";E={
     
    $sum = Get-Datastore -Location $_ |
     
    where {$_.ExtensionData.Summary.MultipleHostAccess -and $_.Type -eq "VMFS"} |
     
    Measure-Object -Property CapacityGB,FreeSpaceGB -Sum
      [
    Math]::Round($sum[0].Sum - $sum[1].Sum,2)
    }}
    |
    Export-Csv c:\scrpits\xxxxx.csv -NoTypeInformation -UseCulture


  • 5.  RE: Total Storage amount in datacenter

    Posted May 24, 2013 05:42 PM

    Thanks for the response. Is it possible for the script to go more granular? It did get the information per Datacenter and now I want it to give me details per cluster. I just changed the Datacenter word to Cluster

    Thanks,



  • 6.  RE: Total Storage amount in datacenter
    Best Answer

    Posted May 24, 2013 06:02 PM

    I'm afraid that it will not work by just changing the Get-Datacenter to Get-Cluster.

    The reason is the Get-Datastore cmdlet later on in the script, on the Location parameter it only accepts Datacenter, Folder, and DatastoreCluster objects.

    But with a small small change we can get it to work for clusters as well.

    Get-Cluster | Select Name,
    @{N="Storage Used (GB)";E={
     
    $sum = Get-Datastore -RelatedObject (Get-VMHost -Location $_) |
     
    where {$_.ExtensionData.Summary.MultipleHostAccess -and $_.Type -eq "VMFS"} |
     
    Measure-Object -Property CapacityGB,FreeSpaceGB -Sum
      [
    Math]::Round($sum[0].Sum - $sum[1].Sum,2)
    }}
    |
    Export-Csv c:\scrpits\xxxxx.csv -NoTypeInformation -UseCulture


  • 7.  RE: Total Storage amount in datacenter

    Posted May 24, 2013 06:07 PM

    Thanks LucD... You are the best.