-
Notifications
You must be signed in to change notification settings - Fork 162
/
Install-WinRMCert.ps1
31 lines (26 loc) · 1.07 KB
/
Install-WinRMCert.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
function Install-WinRMCert($VM)
{
$winRMCert = ($VM | select -ExpandProperty vm).DefaultWinRMCertificateThumbprint
if($winRMCert -eq $null){
$X509=Get-AzureCertificate -ServiceName $vm.serviceName -ThumbprintAlgorithm sha1
if($X509){
$winRMCert=$X509.Thumbprint
}
else {
Write-BoxstarterMessage "Could not find Certificate" -Verbose
return
}
}
Write-BoxstarterMessage "Installing WinRM Certificate"
$AzureX509cert = Get-AzureCertificate -ServiceName $vm.serviceName -Thumbprint $winRMCert -ThumbprintAlgorithm sha1
$certTempFile = [IO.Path]::GetTempFileName()
$AzureX509cert.Data | Out-File $certTempFile
# Target The Cert That Needs To Be Imported
$CertToImport = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certTempFile
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store "Root", "LocalMachine"
$store.Certificates.Count
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$store.Add($CertToImport)
$store.Close()
Remove-Item $certTempFile
}