Skip to content

Get-PSSMSecretInfo

SecretManagement: Retrieves secret metadata from registered vaults

#Requires -Version 5.1
#Requires -Modules Microsoft.PowerShell.SecretManagement, Microsoft.PowerShell.SecretStore

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$SecretName,

    [securestring]$StorePassword,
    [string]$VaultName
)

Process {
    try {
        if ($null -ne $StorePassword) { Unlock-SecretStore -Password $StorePassword -ErrorAction Stop }
        if ([System.String]::IsNullOrWhiteSpace($SecretName)) { $SecretName = '*' }
        $cmdArgs = @{ ErrorAction = 'Stop'; Name = $SecretName }
        if ($PSBoundParameters.ContainsKey('VaultName')) { $cmdArgs.Add('Vault', $VaultName) }
        $result = Get-SecretInfo @cmdArgs -ErrorAction Stop | Select-Object *
        if ($null -ne $result) { foreach ($item in $result) { $item | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force } }
    }
    catch { throw }
}

Name of the secret to query (use * for all)

Password to unlock the SecretStore if required

Name of the vault to search

An interactive directory of PowerShell scripts.