functions/Use-DscEncryptionCertificate.ps1

<#
.SYNOPSIS
Applies certificate to DSC ConfigData
 
.DESCRIPTION
Applies certificate to DSC ConfigData for use with credential secrets, this does not fix the encryption of usernames and passwords in ConfigData strings.
 
.PARAMETER WorkingDirectory
Where is the root / location of where the certificate might be
 
.PARAMETER ConfigData
Configuration Data to be modified
 
 
.EXAMPLE $ConfigData | Use-DscEncryptionCertificate -WorkingDirectory $ReleaseDirectory
#>

function Use-DscEncryptionCertificate {
    [CmdletBinding()]
param(
[HashTable]
[parameter(Mandatory, ValueFromPipeline)]
$ConfigData,
[String]
[Parameter(Mandatory)]
$WorkingDirectory
)
    
    begin {
    }
    
    process {
        foreach ($node in $ConfigData.AllNodes) {
            $certPath = (Join-Path $WorkingDirectory $node.CertificateFile)
            $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certPath
    
            $node.Thumbprint = $cert.Thumbprint
            $node.CertificateFile = $certPath
        }
    }
    
    end {
        $ConfigData
    }
}