functions/secrets/Test-SecretVaultAvailable.ps1

function Test-SecretVaultAvailable {
<#
.SYNOPSIS
Checks whether a specified or default SecretManagement vault is available.
 
.DESCRIPTION
Tests if a specific vault (if provided) is registered in the SecretManagement framework. If no vault name is provided, checks if any vault is registered. Returns $true if the vault exists or at least one vault is available; otherwise, returns $false.
 
.PARAMETER Vault
(Optional) The name of the vault to test. If not specified, the function checks if any vault is registered.
 
.INPUTS
[string] Accepts a vault name from the pipeline or pipeline by property name.
 
.OUTPUTS
[bool] Returns $true if the vault exists or any vault is available; otherwise, $false.
 
.EXAMPLE
Test-SecretVaultAvailable
 
Checks if at least one SecretManagement vault is registered.
 
.EXAMPLE
Test-SecretVaultAvailable -Vault 'MyVault'
 
Checks if the vault named 'MyVault' is registered.
 
.EXAMPLE
'MyVault' | Test-SecretVaultAvailable
 
Checks if 'MyVault' is registered, using pipeline input.
#>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [Alias("VaultName")]
        [string] $Vault
    )

    $params = @{}
    if ($Vault) { $params.Name = $Vault }

    try {
        $null = Get-SecretVault @params
        return Test-SecretVault @params
    }
    catch {
        return $false
    }
}