functions/external-vaults/Get-TssExternalVaultPermissionHistory.ps1
|
function Get-TssExternalVaultPermissionHistory { <# .SYNOPSIS Get the permission change history of an external vault .DESCRIPTION Get the permission change history of an external vault for one permission change. Each permission change writes a shared audit entry; -AuditId picks the change and only the records it wrote are returned. Each record shows a group, the permission it held, who changed it and when, and whether it was removed. .PARAMETER TssSession TssSession object created by New-TssSession for authentication .PARAMETER Id External vault ID .PARAMETER AuditId Shared audit ID of the permission change (audit type ExternalVault, action EDIT PERMISSIONS) .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Get-TssExternalVaultPermissionHistory -TssSession $session -Id 3 -AuditId 1520 Get the permission records that the change audited as 1520 wrote for external vault 3 .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred $change = Search-TssSharedAudit -TssSession $session -AuditType ExternalVault -ItemId 3 | Where-Object Action -eq 'EDIT PERMISSIONS' | Sort-Object DateRecorded -Descending | Select-Object -First 1 Get-TssExternalVaultPermissionHistory -TssSession $session -Id 3 -AuditId $change.AuditId Get the permission records of the latest permission change on external vault 3 .LINK https://thycotic-ps.github.io/thycotic.secretserver/commands/external-vaults/Get-TssExternalVaultPermissionHistory .LINK https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/external-vaults/Get-TssExternalVaultPermissionHistory.ps1 .NOTES Requires TssSession object returned by New-TssSession #> [CmdletBinding()] [OutputType('Thycotic.PowerShell.ExternalVaults.PermissionHistory[]')] param ( [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [Thycotic.PowerShell.Authentication.Session] $TssSession, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('ExternalVaultId')] [int[]] $Id, [Parameter(Mandatory)] [int] $AuditId ) begin { $tssParams = $PSBoundParameters $invokeParams = . $GetInvokeApiParams $TssSession } process { Get-TssInvocation $PSCmdlet.MyInvocation if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { Compare-TssVersion $TssSession '11.7.000000' $PSCmdlet.MyInvocation foreach ($currentId in $Id) { $restResponse = $null $uri = $TssSession.ApiUrl, 'external-vaults', 'vaults', $currentId, 'permission-history' -join '/' $queryParams = @() $queryParams += "take=$($TssSession.Take)" switch ($tssParams.Keys) { 'AuditId' { $queryParams += "filter.auditId=$($AuditId)" } } 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-TssExternalVaultPermissionHistory request' $err = $_ . $ErrorHandling $err } if ($restResponse.records) { [Thycotic.PowerShell.ExternalVaults.PermissionHistory[]](. $FilterTssResponse $restResponse.records ([Thycotic.PowerShell.ExternalVaults.PermissionHistory])) } } } else { Write-Warning 'No valid session found' } } } |