Public/Access/Revoke-SCASession.ps1
|
function Revoke-SCASession { <# .SYNOPSIS Revokes active Secure Cloud Access sessions. .DESCRIPTION Revokes one or more sessions by ID (POST /access/sessions/revoke), or every active session belonging to a user (POST /access/users/{userId}/sessions/revoke). Session IDs can be piped in from Get-SCAActiveSession. .PARAMETER SessionId One or more session IDs to revoke, as returned by Get-SCAActiveSession. .PARAMETER UserId Revoke every active session belonging to this user ID instead of specific session IDs. .PARAMETER Session A psSCA.Session object or session name. Defaults to the current default session. .EXAMPLE Get-SCAActiveSession | Where-Object status -eq 'Active' | Revoke-SCASession Revokes every currently active session. .EXAMPLE Revoke-SCASession -UserId 'a1b2c3d4-user-id' Revokes all active sessions for a specific user. .INPUTS System.String. Session IDs can be piped in by value or by property name from Get-SCAActiveSession. .OUTPUTS psSCA.SessionRevocationInfo .LINK https://api-docs.cyberark.com/sca-api/docs/secure-cloud-access-apis #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High', DefaultParameterSetName = 'BySessionId')] [OutputType('psSCA.SessionRevocationInfo')] param( [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, ParameterSetName = 'BySessionId')] [Alias('id')] [string[]]$SessionId, [Parameter(Mandatory, ParameterSetName = 'ByUser')] [string]$UserId, [Parameter()] [object]$Session ) begin { $collectedIds = [System.Collections.Generic.List[string]]::new() } process { if ($PSCmdlet.ParameterSetName -eq 'BySessionId') { foreach ($id in $SessionId) { $collectedIds.Add($id) } } } end { if ($PSCmdlet.ParameterSetName -eq 'ByUser') { if ($PSCmdlet.ShouldProcess($UserId, 'Revoke all Secure Cloud Access sessions for user')) { Invoke-SCARequest -Session $Session -Service 'SCA' -Method POST -Path '/access/users/{userId}/sessions/revoke' ` -PathParameters @{ userId = $UserId } -Operation 'Revoke-SCASession' -TypeName 'psSCA.SessionRevocationInfo' } return } if ($collectedIds.Count -eq 0) { return } if ($PSCmdlet.ShouldProcess(($collectedIds -join ', '), 'Revoke Secure Cloud Access session(s)')) { Invoke-SCARequest -Session $Session -Service 'SCA' -Method POST -Path '/access/sessions/revoke' ` -Body @{ sessionIds = @($collectedIds) } -Operation 'Revoke-SCASession' -TypeName 'psSCA.SessionRevocationInfo' } } } |