Skip to content

Register-PSSMSecretVault

SecretManagement: Registers a new secret vault

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

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

    [string]$Description,
    [switch]$DefaultVault,
    [switch]$OverwriteExistingVault
)

Process {
    try {
        $cmdArgs = @{ ErrorAction = 'Stop'; ModuleName = 'Microsoft.PowerShell.SecretStore'; Name = $VaultName; AllowClobber = $OverwriteExistingVault; DefaultVault = $DefaultVault; Confirm = $false; PassThru = $null }
        if ($PSBoundParameters.ContainsKey('Description')) { $cmdArgs.Add('Description', $Description) }
        $result = Register-SecretVault @cmdArgs -ErrorAction Stop | Select-Object *
        if ($null -ne $result) { $result | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force }
    }
    catch { throw }
}

Name of the new vault

Optional description for the vault

Off

Set the new vault as the default vault

Off

Overwrite an existing registered vault with the same name

An interactive directory of PowerShell scripts.