-
Notifications
You must be signed in to change notification settings - Fork 0
/
Import-UntrustedGuardian.ps1
53 lines (42 loc) · 1.89 KB
/
Import-UntrustedGuardian.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
<#
.SYNOPSIS
Import Untrusted Guardian certificates
.DESCRIPTION
TPM enabled VMs requires the existence of the Untrusted Guardian certificates stored in the Shielded VM Local Certificates store
In case of a cluster, each node will have their own self signed certificate for this purpose
VM migration requires that the target node must have the same UG certificates as the source node
This script will help to imports certs to the store
.NOTES
Requires administrative access
Version: 1.0
Author: Rózsa Gábor
Creation Date: 2021-06-30
Purpose/Change: Original version
#>
#Requires -RunAsAdministrator
#basic variables
$CertPath = "c:\temp"
Write-Host "Initiating Untrusted Guardian cert import" -ForegroundColor Green
#getting the pfx password
$CertificatePassword = Read-Host -Prompt 'Please enter the password that was used to secure the certificate files' -AsSecureString
#getting all matching certificates
$Certs = Get-ChildItem -Path $CertPath | Where-Object { $_.name -like "*TPM*" -and $_.Extension -eq '.pfx' }
$CertSigning = get-childitem "Cert:\localmachine\Shielded VM Local Certificates" | where-object { $_.Subject -like "*Signing*" }
#looping import
foreach ($cert in $Certs) {
try {
$certshortname = $cert.name.substring(0, 10)
if ($CertSigning.subject -notlike "*$certshortname*") {
$dummy = Import-PfxCertificate -exportable -FilePath $cert -CertStoreLocation "Cert:\localmachine\Shielded VM Local Certificates" -Password $CertificatePassword
Write-Host "$cert.name imported"
}
else {
Write-Host "$cert.name is already present in the store" -ForegroundColor Yellow
}
}
catch {
Write-Host "An error occured importing $cert.name" -ForegroundColor Red
}
}
#finish
Write-Host "Finished importing the UG certs." -ForegroundColor Green