functions/secret-templates/New-TssSecretTemplateExtendedMapping.ps1
|
function New-TssSecretTemplateExtendedMapping { <# .SYNOPSIS Add an extended mapping to a secret template .DESCRIPTION Maps the fields of an extended type, such as an SSH key or certificate type, onto fields of a secret template. Get-TssSecretTemplateExtendedMappingStub returns the extended fields to assign. .PARAMETER TssSession TssSession object created by New-TssSession for authentication .PARAMETER ExtendedTypeId Extended type ID (Search-TssSecretTemplateExtendedType lists them) .PARAMETER SecretTemplateId Secret template ID .PARAMETER Fields Field assignments: objects or hashtables with ExtendedFieldId (a field of the extended type) and SecretFieldId (a field of the secret template). The Fields of Get-TssSecretTemplateExtendedMappingStub output can be passed after SecretFieldId is filled in .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred New-TssSecretTemplateExtendedMapping -TssSession $session -SecretTemplateId 6 -ExtendedTypeId 1 -Fields @{ ExtendedFieldId = 1; SecretFieldId = 108 }, @{ ExtendedFieldId = 2; SecretFieldId = 109 } Maps extended fields 1 and 2 of extended type 1 onto fields 108 and 109 of secret template 6 .LINK https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-templates/New-TssSecretTemplateExtendedMapping .LINK https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-templates/New-TssSecretTemplateExtendedMapping.ps1 .NOTES Requires TssSession object returned by New-TssSession #> [CmdletBinding(SupportsShouldProcess)] [OutputType('Thycotic.PowerShell.SecretTemplates.ExtendedMapping')] param ( [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [Thycotic.PowerShell.Authentication.Session] $TssSession, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [int] $ExtendedTypeId, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('SecretTypeId')] [int] $SecretTemplateId, [Parameter(Mandatory)] [object[]] $Fields ) begin { $tssParams = $PSBoundParameters $invokeParams = . $GetInvokeApiParams $TssSession } process { Get-TssInvocation $PSCmdlet.MyInvocation if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { Compare-TssVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation $uri = $TssSession.ApiUrl, 'secret-templates', $SecretTemplateId, 'extended-mappings', $ExtendedTypeId -join '/' $invokeParams.Uri = $uri $invokeParams.Method = 'POST' $unassigned = @($Fields | Where-Object { $null -eq $_.SecretFieldId }) if ($unassigned) { Write-Error "Every entry in Fields needs a SecretFieldId; missing for ExtendedFieldId $($unassigned.ExtendedFieldId -join ', ')" return } $fieldMap = foreach ($field in $Fields) { @{ extendedFieldId = $field.ExtendedFieldId secretFieldId = $field.SecretFieldId } } $body = @{ data = @{ fields = @($fieldMap) } } $invokeParams.Body = $body | ConvertTo-Json -Depth 100 if ($PSCmdlet.ShouldProcess("Secret template extended mapping: $ExtendedTypeId", "$($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n")) { Write-Verbose "Performing the operation $($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n" try { $apiResponse = Invoke-TssApi @invokeParams $restResponse = . $ProcessResponse $apiResponse } catch { Write-Warning 'Issue with New-TssSecretTemplateExtendedMapping request' $err = $_ . $ErrorHandling $err } if ($restResponse) { [Thycotic.PowerShell.SecretTemplates.ExtendedMapping](. $FilterTssResponse $restResponse ([Thycotic.PowerShell.SecretTemplates.ExtendedMapping])) } } } else { Write-Warning 'No valid session found' } } } |