-
Notifications
You must be signed in to change notification settings - Fork 24
/
InstallRootCertificate.ps1
34 lines (29 loc) · 1.15 KB
/
InstallRootCertificate.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
#Requires -RunAsAdministrator
Param(
[String]
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$commerceContainerName,
[String]
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$password
)
$securepassword = $password | ConvertTo-SecureString -AsPlainText -Force
$hostCertLocation = "$PSScriptRoot\root.pfx"
try{
$containerCertLocation = "C:\files\root.pfx"
docker cp ${commerceContainerName}:${containerCertLocation} $hostCertLocation
if( -Not $?){
throw "Unable to get the root certificate file from ${commerceContainerName}. Possible causes might be that the container is not running or the path $containerCertLocation does not exist in the container."
}
Import-PfxCertificate -FilePath $hostCertLocation -CertStoreLocation 'Cert:\LocalMachine\Root' -Password $securepassword -Verbose
Write-Host "Succesfully imported the root certificate!" -ForegroundColor Green
}finally{
if (Test-Path $hostCertLocation)
{
Write-Host "Cleaning up $hostCertLocation"
Remove-Item $hostCertLocation;
Write-Host "Clean up $hostCertLocation succes!" -ForegroundColor Green
}
}