functions/secret-templates/Get-SecretTemplate.ps1
function Get-SecretTemplate { <# .SYNOPSIS Get a secret template from Secret Server .DESCRIPTION Get a secret template(s) from Secret Server .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Get-TssSecretTemplate -Id 93 Returns secret associated with the Secret ID, 93 .LINK https://thycotic-ps.github.io/thycotic.secretserver/commands/Get-TssSecretTemplate .LINK https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-templates/Get-SecretTemplate.ps1 .NOTES Requires TssSession object returned by New-TssSession #> [cmdletbinding()] [OutputType('TssSecretTemplate')] param( # TssSession object created by New-TssSession for auth [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [TssSession] $TssSession, # Secret template ID to retrieve [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('SecretTemplateId')] [Alias('TemplateId')] [int[]] $Id ) begin { $tssParams = $PSBoundParameters $invokeParams = . $GetInvokeTssParams $TssSession } process { Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { . $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation foreach ($template in $Id) { $restResponse = $null $uri = $TssSession.ApiUrl, 'secret-templates', $template -join '/' $invokeParams.Uri = $Uri $invokeParams.Method = 'GET' Write-Verbose "$($invokeParas.Method) $uri" try { $restResponse = . $InvokeApi @invokeParams } catch { Write-Warning "Issue getting template [$template]" $err = $_ . $ErrorHandling $err } if ($restResponse) { [TssSecretTemplate]$restResponse } } } else { Write-Warning 'No valid session found' } } } |