Get-IpsCredentials.ps1
<# .SYNOPSIS Gets a list of the Image Portability Service credentials in a customer credential wallet. .DESCRIPTION Gets a list of the Image Portability Service credentials in a customer credential wallet. This returns metadata such as the credential name, type and creation data. No secret values (e.g. passwords or keys) are returned. .PARAMETER CustomerId Specifies the customer id of the Citrix customer running this command. .PARAMETER SecureClientId Specifies the client id of the Citrix customer's API client. .PARAMETER SecureSecret Specifies the client secret of the Citrix customer's API client. .PARAMETER CredentialType Specifies the type of credentials to list. If unspecified all types of credential are listed. .PARAMETER Deployment Specifies the service address to send the job request to. It defaults to api.layering.cloud.com. This can be used if necessary to send the request to a geo specific deployment such as api.eu.layering.cloud.com. .PARAMETER LogFileDir Specifies the path to the file to log to. The local directory is the default. .PARAMETER LogFileName Specifies the name of the file to log to. .PARAMETER OverwriteLog If specified the log file is overwritten otherwise it is appended to. .INPUTS None. .OUTPUTS Array of PSCustomObject. List of credential metadata. .EXAMPLE PS> $CitrixCreds = @{ CustomerId = 'a7f4wb1example' SecureClientId = '7fed2a1e-1495-46b7-8fd3-5644764af395' SecureSecret = '9T.3Q~MGlnB6NNgpNUUWrcquVzODrdGK~eXampLe' } PS> Get-IpsCredentials @CitrixCreds -CredentialType Azure | Format-Table Logging to C:\workspace\al\migrationapiclient\test\Credentials.log Verbose False Authenticating for Citrix customer a7f4wb1example using API key 7fed2a1e-1495-46b7-8fd3-5644764af395. Authenticated for Citrix customer a7f4wb1example. Getting credentials from credential wallet id type state createdAt updatedAt -- ---- ----- --------- --------- azure-ips-example Azure Ok 2023-02-02T14:23:32.4047936Z 2023-02-02T14:23:32.4047936Z azure-ips-test Azure Ok 2022-11-22T20:44:37.1097898Z 2022-11-23T18:21:10.3983318Z List all credentials of type 'Azure. #> Function Get-IpsCredentials { [CmdletBinding()] Param( # Citrix Cloud customer id. [Parameter(Mandatory = $true)] [string]$CustomerId, [Parameter(Mandatory = $false)] [ValidateSet("Azure", "Gcp", "UsernamePassword", "Aws")] [string]$CredentialType, # Citrix Cloud credentials. [Parameter(Mandatory = $false)] [string]$SecureClientId, [Parameter(Mandatory = $false)] [string]$SecureSecret, [Parameter(Mandatory = $false)] [string]$Deployment, [Parameter(Mandatory = $false)] [string]$LogFileDir, [Parameter(Mandatory = $false)] [string]$LogFileName = 'Credentials.log', [Parameter(Mandatory = $false)] [switch]$OverwriteLog ) Begin { Add-PSSnapin Citrix.* } Process { # Initialize Logger # Set parameter 'Verbose' by internal parameter 'VerbosePreference', since the option -Verbose is occupied by powershell cmdlet if($VerbosePreference -eq 'Continue') { $Verbose = $True } else { $Verbose = $False } LogInit $LogFileDir $LogFileName $OverwriteLog $Verbose try { # Authenticate to Citrix Cloud $parameters = AuthToCitrixCloud $CustomerId $SecureClientId $SecureSecret if ([string]::IsNullOrWhiteSpace($SecureClientId) -Or [string]::IsNullOrWhiteSpace($SecureSecret)) { $SecureClientId = $parameters.ApiKey $SecureSecret = $parameters.SecretKey } } catch { return } try { LogIt "Getting credentials from credential wallet." $credentialsList = Invoke-CCRestMethod 'Get' $Deployment 'credentials' $CustomerId $SecureClientId $SecureSecret @{} $null if (-not [string]::IsNullOrWhiteSpace($CredentialType)) { LogIt "Listing credentials of type $CredentialType" $False foreach ($credential in $credentialsList.items) { if ($credential.type -eq $CredentialType) { LogIt $credential $False Write-Output $credential } } } else { LogIt "Listing all credentials" $False foreach ($credential in $credentialsList.items) { LogIt $credential $False Write-Output $credential } } } catch { LogFatal "Failed to get the credential list: $_" } } } |