Public/Get-DattoApiConnection.ps1
|
function Get-DattoApiConnection { <# .SYNOPSIS Returns redacted Datto API connection information. .DESCRIPTION Returns connection metadata without exposing the public key or secret key. The public key is represented only by a short suffix hint. .PARAMETER Name Filters by connection name. Wildcards are supported. .PARAMETER Id Filters by connection GUID. .PARAMETER Default Returns only the default connection. .EXAMPLE Get-DattoApiConnection .EXAMPLE Get-DattoApiConnection -Default .OUTPUTS DattoBackupApi.Connection #> [CmdletBinding(DefaultParameterSetName = 'All')] param( [Parameter(ParameterSetName = 'Name')] [SupportsWildcards()] [string]$Name, [Parameter(ParameterSetName = 'Id')] [guid]$Id, [Parameter(Mandatory, ParameterSetName = 'Default')] [switch]$Default ) $states = @($script:DattoApiState.Connections.Values) switch ($PSCmdlet.ParameterSetName) { 'Name' { $states = @($states | Where-Object { $_.Name -like $Name }) } 'Id' { $states = @($states | Where-Object { [string]$_.Id -eq [string]$Id }) } 'Default' { $states = @($states | Where-Object { [string]$_.Id -eq [string]$script:DattoApiState.DefaultConnectionId }) } } foreach ($state in ($states | Sort-Object -Property Name)) { Get-DattoApiConnectionView -ConnectionState $state } } |