functions/devops-secrets-vault/Search-TssDsvTenant.ps1
|
function Search-TssDsvTenant { <# .SYNOPSIS Search DevOps Secrets Vault tenants .DESCRIPTION Lists the DevOps Secrets Vault (DSV) tenants, optionally filtered by name. Inactive tenants are included only with -IncludeInactive. Requires a DevOps Secrets Vault license. .PARAMETER TssSession TssSession object created by New-TssSession for authentication .PARAMETER IncludeInactive Include inactive tenants .PARAMETER SearchText Return tenants whose name matches this text .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Search-TssDsvTenant -TssSession $session List the active DSV tenants .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Search-TssDsvTenant -TssSession $session -SearchText contoso -IncludeInactive List the DSV tenants whose name matches contoso, inactive included .LINK https://thycotic-ps.github.io/thycotic.secretserver/commands/devops-secrets-vault/Search-TssDsvTenant .LINK https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/devops-secrets-vault/Search-TssDsvTenant.ps1 .NOTES Requires TssSession object returned by New-TssSession #> [CmdletBinding()] [OutputType('Thycotic.PowerShell.DevOpsSecretsVault.DsvTenantItem[]')] param ( [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [Thycotic.PowerShell.Authentication.Session] $TssSession, [switch] $IncludeInactive, [string] $SearchText ) 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, 'devops-secrets-vault', 'tenant' -join '/' $queryParams = @() $queryParams += "take=$($TssSession.Take)" switch ($tssParams.Keys) { 'IncludeInactive' { $queryParams += "filter.includeInactive=$([boolean]$IncludeInactive)" } 'SearchText' { $queryParams += "filter.nameSearch=$([uri]::EscapeDataString($SearchText))" } } 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 Search-TssDsvTenant request' $err = $_ . $ErrorHandling $err } if ($restResponse.records) { [Thycotic.PowerShell.DevOpsSecretsVault.DsvTenantItem[]](. $FilterTssResponse $restResponse.records ([Thycotic.PowerShell.DevOpsSecretsVault.DsvTenantItem])) } } else { Write-Warning 'No valid session found' } } } |