LONG DESCRIPTION
Some cmdlets operate on large quantities of data and, to reduce the
overhead of sending all of that data over the network, many of the Get-
cmdlets support server-side filtering of the results.
The conventional way of filtering results in PowerShell is to pipeline
them into Where-Object, Select-Object, and Sort-Object, for example:
Get-<Noun> | Where { $_.Size = 'Small' } | Sort 'Date' | Select -First 10
However, for most XenDesktop cmdlets the data is stored remotely and it
would be slow and inefficient to retrieve large amounts of data over the
network and then discard most of it. Instead, many of the Get- cmdlets
provide filtering parameters that allow results to be processed
on the server, returning only the required results.
You can filter results by most object properties using parameters
derived from the property name. You can also sort results or limit them
to a specified number of records:
Get-<Noun> -Size 'Small' -SortBy 'Date' -MaxRecordCount 10
You can express more complex filter conditions using a syntax and set of
operators very similar to those used by PowerShell expressions.
Those cmdlets that support filtering have the following common parameters:
-MaxRecordCount <int>
Specifies the maximum number of results to return.
For example, to return only the first nine results use:
Get-<Noun> -MaxRecordCount 9
If not specified, only the first 250 records are returned, and if more
are available, a warning is produced:
WARNING: Only first 250 records returned. Use -MaxRecordCount to
retrieve more.
You can suppress this warning by using -WarningAction or by specifying
a value for -MaxRecordCount.
To retrieve all records, specify a large number for -MaxRecordCount.
As the value is an integer, you can use the following:
Get-<Noun> -MaxRecordCount [int]::MaxValue
-ReturnTotalRecordCount [<SwitchParameter>]
When specified, this causes the cmdlet to output an error record
containing the number of records available. This error record is
additional information and does not affect the objects written to the
output pipeline. For example:
Get-<Noun> -MaxRecordCount 9 -ReturnTotalRecordCount
....
Get-<Noun> : Returned 9 of 10 items
At line:1 char:18
+ Get-<Noun> <<<< -MaxRecordCount 9 -ReturnTotalRecordCount
+ CategoryInfo : OperationStopped: (:) [Get-<Noun>], PartialDataException
+ FullyQualifiedErrorId : PartialData,Citrix.<SDKName>.SDK.Get<Noun>
The count can be accessed using the TotalAvailableResultCount property:
$count = $error[0].TotalAvailableResultCount
-Skip <int>
Skips the specified number of records before returning results.
Also reduces the count returned by -ReturnTotalRecordCount.
-SortBy <string>
Sorts the results by the specified list of properties. The list is a
set of property names separated by commas, semi-colons, or spaces.
Optionally, prefix each name with a + or - to indicate ascending or
descending order, respectively. Ascending order is assumed if no
prefix is present.
Sorting occurs before -MaxRecordCount and -Skip parameters are
applied. For example, to sort by Name and then by Count (largest first)
use:
-SortBy 'Name,-Count'
By default, sorting by an enumeration property uses the numeric value
of the elements. You can specify a different sort order by qualifying
the name with an ordered list of elements or their numeric values,
or <null> to indicate the placement of null values.
Elements not mentioned are placed at the end in their numeric order.
For example, to sort by two different enums and then by the object id:
-SortBy 'MyState(StateC,<null>,StateA,StateB),Another(0,3,2,1),Id'
-Filter <String>
This parameter lets you specify advanced filter expressions, and
supports combination of conditions with -and and -or, and grouping
with braces. For example:
Get-<Noun> -Filter 'Name -like "High*" -or (Priority -eq 1 -and Severity -ge 2)'
The syntax is close enough to PowerShell syntax that you can use
script blocks in most cases. This can be easier to read as it reduces
quoting:
Get-<Noun> -Filter { Count -ne $null }
The full -Filter syntax is provided below.