Private/Get-CitrixMachines.ps1
function Get-CitrixMachines { <# .SYNOPSIS Retrieves information about the managed machines for a single Citrix Virtual Apps and Desktops Delivery Controller. .DESCRIPTION This cmdlet returns a custom object with every managed machine hostname, ID and the Delivery Group ID they pertain to for a specific Delivery Controller. The cmdlet does not retrieve information about machines that do not pertain to any Delivery Group or to machines that were previously deleted. .LINK https://github.com/karjona/citrix-odata .PARAMETER DeliveryController Specifies a single Citrix Virtual Apps and Desktops Delivery Controller to collect data from. .PARAMETER Credential Specifies a user account that has permission to send the request. A minimum of read-only administrator permissions on Citrix Virtual Apps and Desktops are required to collect this data. Enter a PSCredential object, such as one generated by the Get-Credential cmdlet. .COMPONENT citrix-odata #> [CmdletBinding()] [OutputType('PSCustomObject')] param( [Parameter(Mandatory=$true)] [String] $DeliveryController, [Parameter()] [PSCredential] $Credential ) process { try { $Query = ( "`$select=HostedMachineId,DnsName,DesktopGroupId&`$filter=(LifecycleState eq 0) and " + "(DesktopGroupId ne null) and (HostedMachineId ne null)" ) $InvokeCitrixMonitorServiceQueryParams = @{ DeliveryController = $DeliveryController Endpoint = 'Machines' Query = $Query ErrorAction = 'Stop' } if ($Credential) { $InvokeCitrixMonitorServiceQueryParams.Add("Credential", $Credential) } Write-Progress -Id 1 -Activity "Retrieving managed machines for $DeliveryController" $Machines = Invoke-CitrixMonitorServiceQuery @InvokeCitrixMonitorServiceQueryParams } catch { $ConnectionError = $_ throw $ConnectionError } finally { Write-Progress -Id 1 -Activity "Retrieving managed machines for $DeliveryController" -Completed } $Machines } } |