-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUpdate-AzKV.ps1
52 lines (43 loc) · 1.34 KB
/
Update-AzKV.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
[CmdletBinding()]
param(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$KeyVaultName,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Secret_Name,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$Secret,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$logon_username,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$logon_password
)
$ErrorActionPreference = "Stop"
$Error.Clear()
#Connect to Azure using Logon Account Creds
try
{
$creds = New-Object -typename System.Management.Automation.PSCredential($logon_username, ($logon_password | ConvertTo-SecureString -AsPlainText -Force))
Connect-AzAccount -Credential $creds
Write-Output "Successfully Connected to Azure using $logon_username"
}
catch
{
Write-Output "Failed to authenticate to Azure. Could be Network Issue or Crednetial issue.`n$($Error[0].Exception)"
}
#Convert the Master Account Password to SecureString
$SecureSecret = $Secret | ConvertTo-SecureString -Force -AsPlainText
#Push/Update the Secret to the Azure KeyVault
try
{
Set-AzKeyVaultSecret -VaultName $KeyVaultName -Name $Secret_Name -SecretValue $SecureSecret
Write-Output "Pushed the secret successfully"
}
catch
{
Write-Output "Failed to update the Secret.`n $($Error[0].Exception)"
}