VMware Cloud Community
Ribcap
Contributor
Contributor
Jump to solution

PowerCli DataStore Audit?

Hello,

I was wondering if someone could help me with a script.  I need to do an audit of our datastores with capacity, provisioned, and available.  I did find a snippet of code which returns the information I need, but is there a way to indicate which cluster these DataStores are assigned to?

Here is the code I'm using.

$report

= @()

get-datastore

| % {

$info = "" | select DataCenter, Name, Capacity, Provisioned, Available

$info.Datacenter = $_.Datacenter

$info.Name = $_.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)

$report += $info

}

#$report | sort Available | format-table –auto

Ideally I'd like to have a spreadsheet with a seperate worksheet for each Cluster, but having a single sheet with all datastores and their cluster would be fine as well.

Thx

Tags (2)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$report = @()

foreach($cluster in Get-Cluster){
    Get-VMHost -Location $cluster | Get-Datastore | %{
        $info = "" | select DataCenter, Cluster, Name, Capacity, Provisioned, Available 
        $info.Datacenter = $_.Datacenter
        $info.Cluster = $cluster.Name
        $info.Name = $_.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) 
        $report += $info
    } }
$report | Export-Csv "C:\cluster-ds.csv" -NoTypeInformation -UseCulture

If you want to have a cluster per worksheet in a spreadsheet, you could use the function from my post called Beyond Export-Csv: Export-Xls

The script would change slightly.

 foreach($cluster in Get-Cluster){
    $report = @()
    Get-VMHost -Location $cluster | Get-Datastore | %{
        $info = "" | select DataCenter, Cluster, Name, Capacity, Provisioned, Available 
        $info.Datacenter = $_.Datacenter
        $info.Cluster = $cluster.Name
        $info.Name = $_.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) 
        $report += $info
    }    
$report | Export-Xls -Path C:\ds-cluster.xls -WorksheetName $cluster.Name -SheetPosition "end"
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
26 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$report = @()

foreach($cluster in Get-Cluster){
    Get-VMHost -Location $cluster | Get-Datastore | %{
        $info = "" | select DataCenter, Cluster, Name, Capacity, Provisioned, Available 
        $info.Datacenter = $_.Datacenter
        $info.Cluster = $cluster.Name
        $info.Name = $_.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) 
        $report += $info
    } }
$report | Export-Csv "C:\cluster-ds.csv" -NoTypeInformation -UseCulture

If you want to have a cluster per worksheet in a spreadsheet, you could use the function from my post called Beyond Export-Csv: Export-Xls

The script would change slightly.

 foreach($cluster in Get-Cluster){
    $report = @()
    Get-VMHost -Location $cluster | Get-Datastore | %{
        $info = "" | select DataCenter, Cluster, Name, Capacity, Provisioned, Available 
        $info.Datacenter = $_.Datacenter
        $info.Cluster = $cluster.Name
        $info.Name = $_.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) 
        $report += $info
    }    
$report | Export-Xls -Path C:\ds-cluster.xls -WorksheetName $cluster.Name -SheetPosition "end"
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Ribcap
Contributor
Contributor
Jump to solution

Thank you soo much!  Both work flawlessly.

I do have a few more questions, but the reports were needed and I can now provide them.  The other items I'm going to try to figure out on my own...hopefully I can better undertand things this way  :smileylaugh:.

Anyways, thanks again....not only for this response, but for all the information that you've given me indirectly.

0 Kudos
ayanes
Contributor
Contributor
Jump to solution

Hi Luc,

I am using this script together with your xls function and it works great.

Is it possible since I am using vsphere 5 with clustered datastores to get the total amount of presented storage in the cluster, total amount of provisioned storage, total amount of used storage per TAB.

Do a formula of presented storage in the cluster minus total amount of provisioned storage. I wanna use this to do storage planning since I am using thin provisioning.

Thanks,

Alberto-

0 Kudos
LucD
Leadership
Leadership
Jump to solution

A datastorecluster is created on the datacenter level.

Are your DSC dedicated to specific clusters, or can a DSC be used from multiple cluster in your environment ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ayanes
Contributor
Contributor
Jump to solution

Each DSC is used by one cluster. Not shared by multiple clusters.

thanks,

Alberto

0 Kudos
ayanes
Contributor
Contributor
Jump to solution

I meant in my environment.

0 Kudos
JT1024
Contributor
Contributor
Jump to solution

I added FreeSpaceMB.  With deduped data, 'available' can show negative values and doesn't always give a good picture to what is really free.

$report = @()

foreach($cluster in Get-Cluster){

    Get-VMHost -Location $cluster | Get-Datastore | %{

        $info = "" | select DataCenter, Cluster, Name, Capacity, FreeSpaceMB, Provisioned, Available

        $info.Datacenter = $_.Datacenter

        $info.Cluster = $cluster.Name

        $info.Name = $_.Name

        $info.Capacity = [math]::Round($_.capacityMB/1024,2)

        $info.FreeSpaceMB = $_.ExtensionData.Summary.FreeSpace/1GB

        $info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)

        $info.Available = [math]::Round($info.Capacity - $info.Provisioned,2)

        $report += $info

    }

}

0 Kudos
russjar
Enthusiast
Enthusiast
Jump to solution

Hi

How do we add VMs on the Datastore to this report?

Cheers

VCP,MCSE NT4/W2k/W2k3, MCSA W2k3
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

$report = @()

foreach($cluster in Get-Cluster){

    foreach($esx in Get-VMHost -Location $cluster){

        foreach($vm in Get-VM -Location $esx){

            Get-Datastore -RelatedObject $vm | %{

                $info = "" | select DataCenter, Cluster, VM, Datastore, Capacity, FreeSpaceMB, Provisioned, Available

                $info.Datacenter = $_.Datacenter

                $info.Cluster = $cluster.Name

                $info.VM = $vm.Name

                $info.Datastore = $_.Name

                $info.Capacity = [math]::Round($_.capacityMB/1024,2)

                $info.FreeSpaceMB = $_.ExtensionData.Summary.FreeSpace/1GB

                $info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)

                $info.Available = [math]::Round($info.Capacity - $info.Provisioned,2)

                $report += $info

            }

        }

    }

}

$report


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
russjar
Enthusiast
Enthusiast
Jump to solution

Champion thank you.

VCP,MCSE NT4/W2k/W2k3, MCSA W2k3
0 Kudos
scottcardinal
Contributor
Contributor
Jump to solution

hi all i'm looking for a script that i can run against a virtual center to see all changes there were made in the last 24 hours on all luns and vms and who made them. new vm's, added memory, or anything that would take up space on a lun that would be a manual change.

thank you in advance!

0 Kudos
raj8
Contributor
Contributor
Jump to solution

Hi Lucd,

could you please provide me the script in getting datastore report in below format

     

NameCapacity GBProvisioned GB  Capacity in %(provisined/capacity) In Use GBFree GBFree %
datastore11290.949218750.740.9492187512899


0 Kudos
icrow1978
Contributor
Contributor
Jump to solution

Hi LucD,

If possible with that script :

$report = @()  foreach($cluster in Get-Cluster){     Get-VMHost -Location $cluster | Get-Datastore | %{         $info = "" | select DataCenter, Cluster, Name, Capacity, Provisioned, Available         $info.Datacenter = $_.Datacenter         $info.Cluster = $cluster.Name         $info.Name = $_.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)         $report += $info
    } } 
$report | Export-Csv "C:\cluster-ds.csv" -NoTypeInformation -UseCulture



Get a report for 2 cluster? or in case that is not possible, get a report for an specfic  cluster e.g Cluster-test .

I test the script and work fine but if a have 2 cluster the script take either cluster-test or cluster-test1.

Best regards

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can specify one or more clusternames on the Get-CLuster cmdlet.

The outer loop could be

foreach($cluster in Get-Cluster -Name cluster-test,cluster-test1)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
icrow1978
Contributor
Contributor
Jump to solution

Hi LucD,

I modify the script with twoo clusters :

foreach($cluster in Get-Cluster -Name HCS-Service,HCS-mgmt){

And i got only a report from HCS-Service.

    

DataCenterClusterNameCapacityProvisionedAvailable
TAHCS-serviceDS_AHTA2PRHCSSVR0301_local2,50,581,92
TAHCS-serviceEMC_HCS_10001023,75591,03432,72
TAHCS-serviceEMC_HCS_10011023,75660,96362,79
TAHCS-serviceEMC_HCS_10041023,75796,26227,49
TAHCS-serviceEMC_HCS_10051023,75832,25191,5
TAHCS-serviceEMC_HCS_10061023,75751,76271,99
TAHCS-serviceEMC_HCS_10071023,75741,85281,9
TAHCS-serviceEMC_HCS_10081023,75862,09161,66

😞

Best regards

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you do just Get-Cluster -Name HCS-Service,HCS-mgmt, it does return two cluster objects ?

You could also try to place the expression (Get-Cluster -Name HCS-Service,HCS-mgmt) between parenthesis.

Otherwise attach the script you are using, there might be something else that goes wrong.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
icrow1978
Contributor
Contributor
Jump to solution

Hi LucD,

With :

PowerCLI C:\PS-Scripts> Get-Cluster -Name HCS-service-mgmt the prompt return twoo cluster.

Name                           HAEnabled  HAFailover DrsEnabled DrsAutomationLe

                                          Level                 vel

----                           ---------  ---------- ---------- ---------------

HCS-service                   True       0          False      FullyAutomated

HCS-mgmt                True       0          False      FullyAutomated

PowerCLI C:\PS-Scripts>

But if a put  the  the expression (Get-Cluster -Name HCS-Service,HCS-mgmt) between parenthesis im only see stats from HCS-X1


best regards


0 Kudos
icrow1978
Contributor
Contributor
Jump to solution

Below the script.

add-PSSnapin VMware.VimAutomation.Core

Connect-VIServer x.x.x.x -Force -User domain\user -Password pass

$fecha = get-date -Format D

foreach($cluster in Get-Cluster -Name HCS-service,HCS-mgmt){

    $report = @()

    Get-VMHost -Location $cluster | Get-Datastore | %{

        $info = "" | select DataCenter, Cluster, Name, Capacity, Provisioned, Available

        $info.Datacenter = $_.Datacenter

        $info.Cluster = $cluster.Name

        $info.Name = $_.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)

        $report += $info

    }

    $report | Export-Csv c:\ReportesvCENTER\ds-cluster$(Get-Date -f yyyyMMdd-hhmm)-$fecha.csv -NoTypeInformation -UseCulture  }

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is because you initialise the array $report inside the Foreach loop.

Move the line $report = @() outside the foreach loop.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference