functions/public/Get-DecryptedString.ps1

function Get-DecryptedString {
    [CmdletBinding()]
    param (
        $encryptionCertificate,
        $encryptedString
    )
    if ($encryptedString.StartsWith("!!enc!!:")) {
        $cleanedEncryptedString = $encryptedString.Replace("!!enc!!:", "")
        $clearTextValue = [System.Text.Encoding]::UTF8.GetString($encryptionCertificate.PrivateKey.Decrypt([System.Convert]::FromBase64String($cleanedEncryptedString), $true))
        return $clearTextValue
    }
    else {
        return $encryptedString
    }
}