Automation

 View Only
  • 1.  Datastore Report

    Posted Feb 16, 2016 11:36 PM

    Hi,

    I'm trying to populate an HTML table with the following but for some reason I'm  not getting the DataStoreCluster name and I'm  not able to filter out LUNS that have a capacity of 1 TB or greater and have less than 1 TB of free space.

    $report = Get-Datastore | Where-Object {$_.Name -notMatch ("ESX|Datastore1") -and ($_.CapacityMB -ge "1000000") -and ($_.FreeSpaceMB -lt "1000000")} | %{

             New-Object PSObject -Property @{

             ClusterName = (Get-DatastoreCluster -Datastore $_ | Select -ExpandProperty Name)

                Name = $_.name         

                Capacity = ($_.CapacityMB * 1MB)

                Provisioned = ($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace +

                $_.ExtensionData.Summary.Uncommitted)

                Used = ($_.CapacityMB * 1MB - $_.FreeSpaceMB * 1MB)

                FreeSpace = ($_.FreeSpaceMB * 1MB)

                PercFree = [math]::Round(100 * $_.FreeSpaceMB/$_.CapacityMB,2)

              

            }

        }    | Sort-Object -Property PercFree

             $report | %{

            writedata $_.ClusterName $_.Name $_.Capacity $_.Provisioned $_.Used $_.FreeSpace $_.PercFree    

            }

    }

    Thanks,



  • 2.  RE: Datastore Report
    Best Answer

    Posted Feb 17, 2016 10:43 AM

    Not sure what writedata is supposed to. Is that a function you wrote.

    And there are unbalanced parenthesis.

    The following works for me

    $report = Get-Datastore |

        Where-Object {$_.Name -notMatch ("ESX|Datastore1") -and

                        ($_.CapacityMB -ge 1TB/1MB) -and

                        ($_.FreeSpaceMB -lt 1TB/1MB)} | %{

             New-Object PSObject -Property @{

                ClusterName = (Get-DatastoreCluster -Datastore $_ | Select -ExpandProperty Name)

                Name = $_.name        

                Capacity = ($_.CapacityMB * 1MB)

                Provisioned = ($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace +

                $_.ExtensionData.Summary.Uncommitted)

                Used = ($_.CapacityMB * 1MB - $_.FreeSpaceMB * 1MB)

                FreeSpace = ($_.FreeSpaceMB * 1MB)

                PercFree = [math]::Round(100 * $_.FreeSpaceMB/$_.CapacityMB,2)

            }

        }    | Sort-Object -Property PercFree

    $report | %{

        Write-Host $_.ClusterName $_.Name $_.Capacity $_.Provisioned $_.Used $_.FreeSpace $_.PercFree   

    }



  • 3.  RE: Datastore Report

    Posted Feb 17, 2016 01:42 PM

    Hi Luc,

    Yes Writedata is a function.

    I get the following error when I run the script as a test attempting to write the output to the command prompt:

    Get-DatastoreCluster : A parameter cannot be found that matches parameter name

    'Datastore'.

    At C:\Scripts\Datastore\test.ps1:16 char:59

    +             ClusterName = (Get-DatastoreCluster -Datastore <<<<  $_ | Select

    -ExpandProperty Name)

        + CategoryInfo          : InvalidArgument: (:) [Get-DatastoreCluster], Par

       ameterBindingException

        + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViC

       re.Cmdlets.Commands.GetDatastoreCluster



  • 4.  RE: Datastore Report

    Posted Feb 18, 2016 11:43 AM

    Which PowerCLi version are you using (do a Get-PowerCLIVersion) ?



  • 5.  RE: Datastore Report

    Posted Feb 18, 2016 12:57 PM

    VMware vSphere PowerCLI 5.0.1 build 581491

    I'm guessing that I should install the latest and greatest and try the code again.

    Thanks



  • 6.  RE: Datastore Report

    Posted Feb 18, 2016 12:59 PM

    Yes, please :smileycool:



  • 7.  RE: Datastore Report

    Posted Feb 18, 2016 06:45 PM

    That was it. After upgrading to version 6.0 the code works like a champ.

    Thanks!