Install-ALOpsCertificate.ps1

function Install-ALOpsCertificate()
{
    param
    (

    )

    Write-Host "*** Check Certificate Setup"
    $CertificateFolder = Join-Path -Path ((get-Module ALOps.ExternalDeployer).ModuleBase) -ChildPath "Certificate"
    $CERFilePath       = Join-Path -Path $CertificateFolder -ChildPath "ALOps-External-Deployer.cer"
    $CERFile           = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 "$($CERFilePath)"
    Write-Host " * Subject : $($CERFile.Subject)"
    Write-Host " * Thumbprint: $($CERFile.Thumbprint)"

    $CheckCertificate = Get-ChildItem cert:\LocalMachine\My -Recurse | Where-Object { $_.Thumbprint -eq "$($CERFile.Thumbprint)" }    
    if ($null -eq $CheckCertificate){
        Write-Host "*** Installing Certificate"

        $PFXFilePath = Join-Path -Path $CertificateFolder -ChildPath "ALOps-External-Deployer.pfx"

        Import-PfxCertificate -FilePath $PFXFilePath `
                              -Password ("$($CERFile.Thumbprint)" | ConvertTo-SecureString -AsPlainText -Force) `
                              -CertStoreLocation Cert:\LocalMachine\my 
    } else {
        Write-Host "*** Certificate already installed"
    }
}