function Unlock-ConfigurationDataSecretManagementVault { [CmdletBinding()] Param( [Parameter(Mandatory=$false)] [hashtable] $ProviderSettings = @{} ) if(-not $ProviderSettings.ContainsKey("SecretManagement")){ return } $SecretManagementSettings = $ProviderSettings.SecretManagement if(-not ($SecretManagementSettings -is [System.Collections.IDictionary])){ return } if(-not (Test-ConfigurationDataMapContainsKey -Map $SecretManagementSettings -Key "MasterPassword")){ return } $Vault = [string](Get-ConfigurationDataMapValue -Map $SecretManagementSettings -Key "DefaultVault" -DefaultValue "") if([string]::IsNullOrWhiteSpace($Vault)){ throw "SecretManagement provider settings define [MasterPassword], but [DefaultVault] is not defined." } $UnlockSecretVaultCommand = Get-Command -Name Unlock-SecretVault -ErrorAction SilentlyContinue if($null -eq $UnlockSecretVaultCommand){ throw "Command [Unlock-SecretVault] was not found. Install module [Microsoft.PowerShell.SecretManagement]." } $MasterPassword = Resolve-ConfigurationDataProviderSecureString -Value $SecretManagementSettings.MasterPassword & $UnlockSecretVaultCommand -Name $Vault -Password $MasterPassword $TestSecretVaultCommand = Get-Command -Name Test-SecretVault -ErrorAction SilentlyContinue if($null -ne $TestSecretVaultCommand){ $IsUnlocked = $false try { $IsUnlocked = [bool](& $TestSecretVaultCommand -Name $Vault -ErrorAction Stop) } catch { throw "SecretManagement vault [$Vault] could not be unlocked. $($_.Exception.Message)" } if(-not $IsUnlocked){ throw "SecretManagement vault [$Vault] could not be unlocked. Verify the KeePass database path, KeePass key file, and protected master password in the provider settings." } } }