functions/secrets/Get-TssSecretMfa.ps1
|
function Get-TssSecretMfa { <# .SYNOPSIS Test whether a secret requires multifactor authentication .DESCRIPTION Returns True when the secret requires multifactor authentication to view it, False otherwise. Secret Server audits the request as a secret view. .PARAMETER TssSession TssSession object created by New-TssSession for authentication .PARAMETER Id Secret ID .PARAMETER IncludeInactive Include the secret when it is inactive .PARAMETER NoAutoCheckout Do not check out the secret automatically .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Get-TssSecretMfa -TssSession $session -Id 42 Returns True when secret 42 requires multifactor authentication .LINK https://thycotic-ps.github.io/thycotic.secretserver/commands/secrets/Get-TssSecretMfa .LINK https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secrets/Get-TssSecretMfa.ps1 .NOTES Requires TssSession object returned by New-TssSession #> [CmdletBinding()] [OutputType('System.Boolean')] param ( [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [Thycotic.PowerShell.Authentication.Session] $TssSession, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('SecretId')] [int] $Id, [switch] $IncludeInactive, [switch] $NoAutoCheckout ) 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, 'secrets', $Id, 'mfa' -join '/' $queryParams = @() switch ($tssParams.Keys) { 'IncludeInactive' { $queryParams += "includeInactive=$([boolean]$IncludeInactive)" } 'NoAutoCheckout' { $queryParams += "noAutoCheckout=$([boolean]$NoAutoCheckout)" } } if ($queryParams) { $uri = $uri, ($queryParams -join '&') -join '?' } $invokeParams.Uri = $uri $invokeParams.Method = 'GET' Write-Verbose "Performing the operation $($invokeParams.Method) $uri" try { $apiResponse = Invoke-TssApi @invokeParams $restResponse = . $ProcessResponse $apiResponse } catch { Write-Warning 'Issue with Get-TssSecretMfa request' $err = $_ . $ErrorHandling $err } if ($null -ne $restResponse) { [System.Convert]::ToBoolean($restResponse) } } else { Write-Warning 'No valid session found' } } } |