functions/folders/Remove-TssFolder.ps1
function Remove-TssFolder { <# .SYNOPSIS Delete secret folder .DESCRIPTION Delete secret folder .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Remove-TssFolder -TssSession $session -Id 28 Delete Folder ID 28 .LINK https://thycotic-ps.github.io/thycotic.secretserver/commands/folders/Remove-TssFolder .LINK https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/folders/Remove-TssFolder.ps1 .NOTES Requires TssSession object returned by New-TssSession #> [CmdletBinding(SupportsShouldProcess)] [OutputType('Thycotic.PowerShell.Common.Delete')] param ( # TssSession object created by New-TssSession for authentication [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [Thycotic.PowerShell.Authentication.Session] $TssSession, # Folder ID [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('FolderId')] [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 ($folder in $Id) { $restResponse = $null $uri = $TssSession.ApiUrl, 'folders', $folder -join '/' $invokeParams.Uri = $uri $invokeParams.Method = 'DELETE' if ($PSCmdlet.ShouldProcess("FolderId: $folder", "$($invokeParams.Method) $($invokeParams.Uri)")) { Write-Verbose "Performing the operation $($invokeParams.Method) $uri with $body" try { $apiResponse = Invoke-TssApi @invokeParams $restResponse = . $ProcessResponse $apiResponse } catch { Write-Warning 'Issue removing folder [$folder]' $err = $_ . $ErrorHandling $err } if ($restResponse) { [Thycotic.PowerShell.Common.Delete]$restResponse } } } } else { Write-Warning 'No valid session found' } } } |