-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set-AzureCertificate.ps1
69 lines (62 loc) · 2.12 KB
/
Set-AzureCertificate.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
62
63
64
65
66
67
68
69
function Set-AzureCertificate
{
<#
.Synopsis
Add a certificate to Azure Vault
.DESCRIPTION
Add a certificate set to Azure Vault. Run Connect-AzureCredentialVault prior to running this command.
.EXAMPLE
Set-AzureCertificate -Path C:\mycert.pfx -Name MyCert
cmdlet Set-AzureCertificate at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
Password:**************
.EXAMPLE
$Password = Read-Host -AsSecureString
Set-AzureCertificate -Path C:\mycert.pfx -Name MyCert -Password $Password
#>
[CmdletBinding()]
[Alias()]
Param
(
# Path to PFX or PEM file
[Parameter(Mandatory=$true, Position=0)]
$Path,
[Parameter(Mandatory=$true, Position=1,HelpMessage="Supply a name for the certificate")]
$Name,
# Password needs to be a secure string
[Parameter(Mandatory=$true, Position=2,HelpMessage="Supply the password as a System.Security.SecureString")]
[alias("SecurePassword")]
[Security.SecureString]$Password,
[Parameter(Mandatory=$true, Position=3,HelpMessage="Supply the resource group name to use")]
$ResourceGroupName,
[Parameter(Mandatory=$true, Position=4,HelpMessage="Supply the storage account name to use")]
$StorageAccountName,
[Parameter(Mandatory=$true, Position=5,HelpMessage="Supply the vault name")]
$VaultName,
$TableName,
$PartitionKey,
[Switch]$Force
)
Begin
{
if (!$Global:VaultSA)
{
Connect-AzureCredentialVault -ResourceGroupName $ResourceGroupName -StorageAccountName $StorageAccountName -VaultName $VaultName
}
}
Process
{
try{
Import-AzureKeyVaultCertificate -VaultName $VaultName -Name $Name -FilePath $Path -Password $Password -ErrorAction stop | Out-Null
Write-Verbose "$Name has been aded to $VaultName"
}
catch {
Write-Warning -Message $_.Exception.Message
continue
}
}
End
{
}
}