Public/Get-3PARCpgs.ps1

Function Get-3PARCpgs {

  <#
      .SYNOPSIS
      Retrieve informations about CPGs
      .DESCRIPTION
      This function will retrieve informations about CPGs. You need to have an active session with the array.
      .NOTES
      Written by Erwan Quelin under Apache licence
      .LINK
      https://github.com/equelin/3PAR-Powershell
      .EXAMPLE
      Get-3PARCpgs
      List all the CPGs
      .EXAMPLE
      Get-3PARCpgs -Name 'SSD-RAID1'
      Retrieve information about the CPG named SSD-RAID1
  #>


  [CmdletBinding()]
  Param(
      [Parameter(Mandatory = $false,HelpMessage = 'CPG Name')]
      [String]$name
  )

  # Test if connection exist
  Check-3PARConnection

  #Request
  $data = Send-3PARRequest -uri '/cpgs'

  # Results
  $dataPS = ($data.content | ConvertFrom-Json).members
  $dataCount = ($data.content | ConvertFrom-Json).total

  # Add custom type to the resulting oject for formating purpose
  $AlldataPS = @()

  Foreach ($data in $dataPS) {
    $data = Add-ObjectDetail -InputObject $data -TypeName '3PAR.Cpgs'
    If (!($data.ID -eq $null)) {
        $AlldataPS += $data
    }
  }

  #Write result + Formating
  Write-Verbose "Total number of CPGs: $($dataCount)"
  If ($name) {
      Write-Verbose "Return result(s) with the filter: $($name)"
      return $AlldataPS | Where-Object -FilterScript {$_.Name -like $name}
  } else {
      Write-Verbose "Return result(s) without any filter"
      return $AlldataPS
  }
}