5 Replies Latest reply on Nov 15, 2019 4:22 PM by Mark Brookfield

    Trying to replace characters to format PEM certificate into one line

    Mark Brookfield Enthusiast
    vExpert

      Hi,

       

      I'm trying to format a PEM certificate into one line so I can use it in a JSON request to replace Horizon UAG certs.

       

      So instead of:

       

      -----BEGIN CERTIFICATE-----

      MIIF3DCCBMSgAwIBAgISBCkuTZLrEXMdLGqMq4wmzVgvMA0GCSqGSIb3DQEBCwUA

      MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD

      ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xOTExMTMwMDIwMjhaFw0y

      MDAyMTEwMDIwMjhaMB4xHDAaBgNVBAMTE3ZkaS5ob2JiaXRjbG91ZC5jb20wggGi

      MA0GCSqGSIb3DQEBAQUAA4IBjwAwggGK

       

      I get:

       

      -----BEGIN CERTIFICATE-----\nMIIF3DCCBMSgAwIBAgISBCkuTZLrEXMdLGqMq4wmzVgvMA0GCSqGSIb3DQEBCwUA\nMEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD\nExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xOTExMTMwMDIwMjhaFw0y\nMDAyMTEwMDIwMjhaMB4xHDAaBgNVBAMTE3ZkaS5ob2JiaXRjbG91ZC5jb20wggGi\nMA

       

      (notice the "\n" that embedded).

       

      I can do it in Awk using:

       

      awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' cert-name.pem
      

       

      However, I need to achieve the same in PowerCLI.

       

      I'm trying variations of

       

      $cert = (Get-Content vdi.hobbitcloud.com-chain.pem' | Out-String) -replace "`r?`n(?!`r?`n)" 
      

       

      But can't seem to manage it.

       

      Does anyone have any ideas on what I need to use?

       

      Many thanks,

       

       

      -Mark