Get-PSSMSecret
SecretManagement: Retrieves a secret from a registered vault
#Requires -Version 5.1
#Requires -Modules Microsoft.PowerShell.SecretManagement, Microsoft.PowerShell.SecretStore
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$SecretName,
[securestring]$StorePassword,
[string]$VaultName,
[switch]$AsPlainText
)
Process {
try {
if ($null -ne $StorePassword) { Unlock-SecretStore -Password $StorePassword -ErrorAction Stop }
$cmdArgs = @{ ErrorAction = 'Stop'; Name = $SecretName; AsPlainText = $AsPlainText }
if ($PSBoundParameters.ContainsKey('VaultName')) { $cmdArgs.Add('Vault', $VaultName) }
$sec = Get-Secret @cmdArgs -ErrorAction Stop
if ($null -ne $sec) { [PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; SecretName = $SecretName; Value = $sec.ToString() } }
}
catch { throw }
}Name of the secret to retrieve
Password to unlock the SecretStore if required
Name of the vault to search
Off
Return the secret as a plain text string