Pulling keys from *.pem file to store in AWS Secrets Manager

I am trying to find a way to pull the public and private key from a self-signed cert I created on a Windows server 2019 to store in secrets manager for other servers to be able to use for credentials encryption in PowerShell DSC *.mof files. I can export the cert as a *.pem file. I have been told this can be done with openssl commands, I would rather do it with PowerShell, but if there are advantages to using openssl, I am glad to hear it.

If you have it as a PEM file that looks something like this example:
Example PEM File (docs.progress.com)

Could you use a regex to pull the necessary info?

$pem = Get-Content E:\Temp\Files\example.pem -Raw

$pem -match "(-+BEGIN PRIVATE KEY-+[\s\S]*-+END PRIVATE KEY-+)|(-+BEGIN CERTIFICATE-+[\s\S]*-+END CERTIFICATE-+)"

$matches[0]
$matches[1]