functions/users/Remove-TssUser.ps1
|
function Remove-TssUser { <# .SYNOPSIS Delete a user, which deactivates the account .DESCRIPTION Sends DELETE for each user ID. Secret Server does not erase the user: it disables the account and records the change in the user audit. Fails with access denied for a user that is already disabled, a system user, the calling user or a Platform service user. .PARAMETER TssSession TssSession object created by New-TssSession for authentication .PARAMETER Id ID of the user to delete .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Remove-TssUser -TssSession $session -Id 42 Deletes (deactivates) user 42 .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Search-TssUser -TssSession $session -SearchText olduser | Remove-TssUser -TssSession $session -WhatIf Shows which users matching olduser would be deleted .LINK https://thycotic-ps.github.io/thycotic.secretserver/commands/users/Remove-TssUser .LINK https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/users/Remove-TssUser.ps1 .NOTES Requires TssSession object returned by New-TssSession #> [CmdletBinding(SupportsShouldProcess)] [OutputType('Thycotic.PowerShell.Common.Delete')] param ( [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [Thycotic.PowerShell.Authentication.Session] $TssSession, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('UserId')] [int[]] $Id ) 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 foreach ($currentId in $Id) { $restResponse = $null $uri = $TssSession.ApiUrl, 'users', $currentId -join '/' $invokeParams.Uri = $uri $invokeParams.Method = 'DELETE' if ($PSCmdlet.ShouldProcess("User: $currentId", "$($invokeParams.Method) $uri")) { Write-Verbose "Performing the operation $($invokeParams.Method) $uri" try { $apiResponse = Invoke-TssApi @invokeParams $restResponse = . $ProcessResponse $apiResponse } catch { Write-Warning 'Issue with Remove-TssUser request' $err = $_ . $ErrorHandling $err } if ($restResponse) { [Thycotic.PowerShell.Common.Delete](. $FilterTssResponse $restResponse ([Thycotic.PowerShell.Common.Delete])) } } } } else { Write-Warning 'No valid session found' } } } |