-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecretManagement-Sample.ps1
61 lines (47 loc) · 1.89 KB
/
SecretManagement-Sample.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
$modules = @(
"Microsoft.PowerShell.SecretManagement",
"Microsoft.PowerShell.SecretStore",
"SecretManagement.Chromium",
"SecretManagement.KeePass"
)
Install-Module -Name $modules
#region : Keepass
# Set path to KeePass file and test it exists
$KeePassDBFilePath = ".\keepass\database.kdbx"
# set up the value for the VaultParameters parameter
$parameters = @{
Path = $KeePassDBFilePath
UseMasterPassword = $true
MasterPassword = "pwd"
}
# Set a vault name and if it exists then unregister that vault in this session
$vaultName = 'keepass-vault-01'
if (Get-SecretVault -Name $vaultName -ErrorAction SilentlyContinue)
{
Unregister-SecretVault $vaultName
}
# register our chosen vault
Register-SecretVault -Name $vaultName -ModuleName SecretManagement.keepass -VaultParameters $parameters
Test-SecretVault -Name $vaultName
# get secret from keepass vault
$secret = Get-Secret -Vault $vaultName -Name "Sample Entry"
$secret.GetNetworkCredential().Password
# set new secret
Set-Secret -Name 'Anton' -Vault $vaultName -Secret '@_thisIsAT3st!'
# return secret meta info
Get-SecretInfo -Vault $vaultName
#endregion
#region : Azure Key Vault
# azure key vault
Install-Module Az.KeyVault
Register-SecretVault -Module Az.KeyVault -Name AzKV -VaultParameters @{ AZKVaultName = $vaultName; SubscriptionId = $subID}
#endregion
#region : Local Secret Store
# scenario automation
Install-Module -Name Microsoft.PowerShell.SecretStore -Repository PSGallery -Force
$password = Import-CliXml -Path $securePasswordPath
Set-SecretStoreConfiguration -Scope CurrentUser -Authentication Password -PasswordTimeout 3600 -Interaction None -Password $password -Confirm:$false
Install-Module -Name Microsoft.PowerShell.SecretManagement -Repository PSGallery -Force
Register-SecretVault -Name SecretStore -ModuleName Microsoft.PowerShell.SecretStore -DefaultVault
Unlock-SecretStore -Password $password
#endregion