Remove-PSSMSecret
SecretManagement: Removes a secret from a vault
#Requires -Version 5.1
#Requires -Modules Microsoft.PowerShell.SecretManagement, Microsoft.PowerShell.SecretStore
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$SecretName,
[Parameter(Mandatory = $true)]
[string]$VaultName,
[securestring]$StorePassword
)
Process {
try {
if ($null -ne $StorePassword) { Unlock-SecretStore -Password $StorePassword -ErrorAction Stop }
$cmdArgs = @{ ErrorAction = 'Stop'; Name = $SecretName; Vault = $VaultName; Confirm = $false }
Remove-Secret @cmdArgs -ErrorAction Stop
[PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; Status = "Success"; SecretName = $SecretName; VaultName = $VaultName; Message = "Secret '$SecretName' removed from vault '$VaultName'" }
}
catch { throw }
}Name of the secret to remove
Name of the vault containing the secret
Password to unlock the SecretStore if required