private void RemoveParamSecrets( Hashtable vaultInfo, string ParametersNameKey) { if (vaultInfo != null && vaultInfo.ContainsKey(ParametersNameKey)) { var parametersName = (string)vaultInfo[ParametersNameKey]; if (!string.IsNullOrEmpty(parametersName)) { int errorCode = 0; if (!LocalSecretStore.DeleteObject(parametersName, ref errorCode)) { var errorMessage = LocalSecretStore.GetErrorMessage(errorCode); var msg = string.Format(CultureInfo.InvariantCulture, "Removal of vault info script parameters {0} failed with error {1}", parametersName, errorMessage); WriteError( new ErrorRecord( new PSInvalidOperationException(msg), "UnregisterSecretsVaultRemoveScriptParametersFailed", ErrorCategory.InvalidOperation, this)); } } } }
protected override void ProcessRecord() { if (Vault.Equals(RegisterSecretVaultCommand.BuiltInLocalVault, StringComparison.OrdinalIgnoreCase)) { // Remove from local built-in default vault. int errorCode = 0; if (!LocalSecretStore.DeleteObject( name: Name, ref errorCode)) { var errorMessage = LocalSecretStore.GetErrorMessage(errorCode); var msg = string.Format(CultureInfo.InvariantCulture, "The secret could not be removed from the local default vault. Error: {0}", errorMessage); ThrowTerminatingError( new ErrorRecord( new PSInvalidOperationException(msg), "RemoveSecretCannotDelete", ErrorCategory.InvalidOperation, this)); } else { WriteVerbose( string.Format("Secret {0} was successfully removed from vault {1}.", Name, RegisterSecretVaultCommand.BuiltInLocalVault)); } return; } // Remove from extension vault. var extensionModule = GetExtensionVault(Vault); extensionModule.InvokeRemoveSecret( name: Name, vaultName: Vault, cmdlet: this); }