Skip to content

Commit 6b40920

Browse files
Azure KeyVault scripts
1 parent a273c73 commit 6b40920

45 files changed

Lines changed: 3115 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#Requires -Version 5.0
2+
#Requires -Modules Az.KeyVault
3+
4+
<#
5+
.SYNOPSIS
6+
Adds a certificate to a key vault
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
16+
© ScriptRunner Software GmbH
17+
18+
.COMPONENT
19+
Requires Module Az.KeyVault
20+
21+
.LINK
22+
https://github.com/scriptrunner/ActionPacks/blob/master/Azure/KeyVault
23+
24+
.Parameter VaultName
25+
[sr-en] Name of the key vault
26+
[sr-de] Namen des Key Vaults
27+
28+
.Parameter Destination
29+
[sr-en] Add the key as a software-protected key or an HSM-protected key
30+
[sr-de] Schlüssel als softwaregeschützten Schlüssel oder als HSM-geschützten Schlüssel hinzufügen
31+
32+
.Parameter Name
33+
[sr-en] Name of the certificate to add
34+
[sr-de] Namen des Zertifikats
35+
36+
.PARAMETER CurveName
37+
[sr-en] Elliptic curve name of the key of the certificate
38+
[sr-de] Elliptic curve name des Zertifikatsschlüssels
39+
40+
.PARAMETER IssuerName
41+
[sr-en] Name of the issuer for the certificate
42+
[sr-de] Name des Ausstellers des Zertifikats
43+
44+
.PARAMETER SubjectName
45+
[sr-en] Subject name of the certificate for policy
46+
[sr-de] Name des Zertifikats der Policy
47+
48+
.PARAMETER SecretContentType
49+
[sr-en] Name of the issuer for the certificate
50+
[sr-de] Name des Ausstellers des Zertifikats
51+
52+
.PARAMETER KeyNotExportable
53+
[sr-en] Key is not exportable
54+
[sr-de] Schlüssel des Zertifikats kann nicht exportiert werden
55+
56+
.Parameter KeySize
57+
[sr-en] Key size of the certificate
58+
[sr-de] Schlüsselgröße des Zertifikats
59+
60+
.PARAMETER KeyType
61+
[sr-en] Key type of the key that backs the certificate
62+
[sr-de] Typ des Schlüssels
63+
64+
.PARAMETER ValidityInMonths
65+
[sr-en] Number of months the certificate is valid
66+
[sr-de] Anzahl der Monate, in denen das Zertifikat gültig ist
67+
#>
68+
69+
param(
70+
[Parameter(Mandatory = $true)]
71+
[string]$VaultName,
72+
[Parameter(Mandatory = $true)]
73+
[string]$Name,
74+
[Parameter(Mandatory = $true)]
75+
[string]$IssuerName,
76+
[Parameter(Mandatory = $true)]
77+
[string]$SubjectName,
78+
[ValidateSet('application/x-pkcs12','application/x-pem-file')]
79+
[string]$SecretContentType = 'application/x-pkcs12',
80+
[ValidateSet('P-256','P-384','P-521','P-256K','SECP256K1')]
81+
[string]$CurveName,
82+
[switch]$KeyNotExportable,
83+
[ValidateSet('RSA','RSA-HSM','EC','EC-HSM')]
84+
[string]$KeyType,
85+
[ValidateSet('256','384','521','2048','3072','4096')]
86+
[string]$KeySize,
87+
[int]$ValidityInMonths = 6
88+
)
89+
90+
Import-Module Az.KeyVault
91+
92+
try{
93+
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
94+
'IssuerName' = $IssuerName
95+
'SubjectName' = $SubjectName
96+
'SecretContentType' = $SecretContentType
97+
'ValidityInMonths' = $ValidityInMonths
98+
'Confirm' = $false
99+
}
100+
if($PSBoundParameters.ContainsKey('CurveName') -eq $true){
101+
$cmdArgs.Add('Curve',$CurveName)
102+
}
103+
if($PSBoundParameters.ContainsKey('KeySize') -eq $true){
104+
$cmdArgs.Add('KeySize',$KeySize)
105+
}
106+
if($PSBoundParameters.ContainsKey('KeyType') -eq $true){
107+
$cmdArgs.Add('KeyType',$KeyType)
108+
}
109+
if($KeyNotExportable.IsPresent -eq $true){
110+
$cmdArgs.Add('KeyNotExportable',$null)
111+
}
112+
$cerPolicy = New-AzKeyVaultCertificatePolicy @cmdArgs
113+
114+
$cmdArgs = @{'ErrorAction' = 'Stop'
115+
'Name' = $Name
116+
'CertificatePolicy' = $cerPolicy
117+
'VaultName' = $VaultName
118+
'Confirm' = $false
119+
}
120+
$ret = Add-AzKeyVaultCertificate @cmdArgs | Select-Object *
121+
122+
if($null -ne $SRXEnv) {
123+
$SRXEnv.ResultMessage = $ret
124+
}
125+
else{
126+
Write-Output $ret
127+
}
128+
}
129+
catch{
130+
throw
131+
}
132+
finally{
133+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#Requires -Version 5.0
2+
#Requires -Modules Az.KeyVault
3+
4+
<#
5+
.SYNOPSIS
6+
Adds a contact for certificate notifications
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
16+
© ScriptRunner Software GmbH
17+
18+
.COMPONENT
19+
Requires Module Az.KeyVault
20+
21+
.LINK
22+
https://github.com/scriptrunner/ActionPacks/blob/master/Azure/KeyVault
23+
24+
.Parameter VaultName
25+
[sr-en] Name of the key vault
26+
[sr-de] Name des Key-Vaults
27+
28+
.Parameter MailAddress
29+
[sr-en] Email address of the contact
30+
[sr-de] Mailadresse des Kontakts
31+
#>
32+
33+
param(
34+
[Parameter(Mandatory = $true)]
35+
[string]$VaultName,
36+
[Parameter(Mandatory = $true)]
37+
[string]$MailAddress
38+
)
39+
40+
Import-Module Az.KeyVault
41+
42+
try{
43+
if($Properties -contains '*'){
44+
$Properties = @('*')
45+
}
46+
47+
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
48+
'VaultName' = $VaultName
49+
'EmailAddress' = $MailAddress
50+
'Confirm' = $false
51+
'PassThru' = $null
52+
}
53+
$result = Add-AzKeyVaultCertificateContact @cmdArgs | Select-Object $Properties
54+
55+
if($null -ne $SRXEnv) {
56+
$SRXEnv.ResultMessage = $result
57+
}
58+
else{
59+
Write-Output $result
60+
}
61+
}
62+
catch{
63+
throw
64+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#Requires -Version 5.0
2+
#Requires -Modules Az.KeyVault
3+
4+
<#
5+
.SYNOPSIS
6+
Creates a key in a key vault or imports a key into a key vault
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
16+
© ScriptRunner Software GmbH
17+
18+
.COMPONENT
19+
Requires Module Az.KeyVault
20+
21+
.LINK
22+
https://github.com/scriptrunner/ActionPacks/blob/master/Azure/KeyVault
23+
24+
.Parameter VaultName
25+
[sr-en] Name of the key vault
26+
[sr-de] Namen des Key Vaults
27+
28+
.Parameter Destination
29+
[sr-en] Add the key as a software-protected key or an HSM-protected key
30+
[sr-de] Schlüssel als softwaregeschützten Schlüssel oder als HSM-geschützten Schlüssel hinzufügen
31+
32+
.Parameter Name
33+
[sr-en] Name of the key to add to the key vault
34+
[sr-de] Namen des Schlüssels
35+
36+
.Parameter KeyType
37+
[sr-en] Key type of this key
38+
[sr-de] Schlüssel-Typ
39+
#>
40+
41+
param(
42+
[Parameter(Mandatory = $true)]
43+
[string]$VaultName,
44+
[Parameter(Mandatory = $true)]
45+
[ValidateSet('HSM','Software')]
46+
[string]$Destination,
47+
[Parameter(Mandatory = $true)]
48+
[string]$Name,
49+
[ValidateSet('EC','RSA','oct')]
50+
[string]$KeyType
51+
)
52+
53+
Import-Module Az.KeyVault
54+
55+
try{
56+
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
57+
'Name' = $Name
58+
'Destination' = $Destination
59+
'VaultName' = $VaultName
60+
'Confirm' = $false
61+
}
62+
63+
if($PSBoundParameters.ContainsKey('KeyType') -eq $true){
64+
$cmdArgs.Add('KeyType',$KeyType)
65+
}
66+
$ret = Add-AzKeyVaultKey @cmdArgs
67+
68+
if($null -ne $SRXEnv) {
69+
$SRXEnv.ResultMessage = $ret
70+
}
71+
else{
72+
Write-Output $ret
73+
}
74+
}
75+
catch{
76+
throw
77+
}
78+
finally{
79+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#Requires -Version 5.0
2+
#Requires -Modules Az.KeyVault
3+
4+
<#
5+
.SYNOPSIS
6+
Backs up a certificate in a key vault
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
16+
© ScriptRunner Software GmbH
17+
18+
.COMPONENT
19+
Requires Module Az.KeyVault
20+
21+
.LINK
22+
https://github.com/scriptrunner/ActionPacks/blob/master/Azure/KeyVault
23+
24+
.Parameter VaultName
25+
[sr-en] Name of the key vault
26+
[sr-de] Name des Key-Vaults
27+
28+
.Parameter CertificateName
29+
[sr-en] Name of the certificate
30+
[sr-de] Name des Zertifikats
31+
32+
.Parameter BackupPath
33+
[sr-en] The output file to store the backup of the certificate
34+
[sr-de] Name und Pfad der Exportdatei
35+
#>
36+
37+
param(
38+
[Parameter(Mandatory = $true)]
39+
[string]$VaultName,
40+
[Parameter(Mandatory = $true)]
41+
[string]$CertificateName,
42+
[Parameter(Mandatory = $true)]
43+
[string]$BackupPath
44+
)
45+
46+
Import-Module Az.KeyVault
47+
48+
try{
49+
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
50+
'VaultName' = $VaultName
51+
'Name' = $CertificateName
52+
'OutputFile' = $BackupPath
53+
Confirm = $false
54+
Force = $null
55+
}
56+
$result = Backup-AzKeyVaultCertificate @cmdArgs
57+
58+
if($null -ne $SRXEnv) {
59+
$SRXEnv.ResultMessage = $result
60+
}
61+
else{
62+
Write-Output $result
63+
}
64+
}
65+
catch{
66+
throw
67+
}

0 commit comments

Comments
 (0)