I expanded on your script a bit in case people are struggling, and it opens a the output file afterwards also. Run it in PowerShell_ISE or VSCode (or Terminal>Powershell if you edit the paths at the top first):
$myCert = "C:\Temp\mycert.cer"
$outputDir = "C:\temp\mycertoutput"
#=========== No changes below ==========
$output = $outputDir+'\'+"CertOutput.txt"
# Import the certificate as an object
$certObj = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($mycert)
# Test and create output directory if needed
If(-Not(Test-Path $outputDir)) { New-Item -ItemType Directory $outputDir | Out-Null }
#Get Cert properties
$certpath= (get-item $myCert).FullName
$subject = $certObj.SubjectName.Name
$thumbprint = $certObj.Thumbprint
$OMA_URI = "./Device/Vendor/MSFT/RootCATrustedCertificates/TrustedPublisher/$thumbprint/EncodedCertificate"
$certContent = [System.Convert]::ToBase64String($certObj.Export('Cert'))
# Output cert info to output file and open file
"Imported Cert Path: $certpath" >> $output
"`nSubject: $subject" >> $output
"`nThumbprint: $thumbprint" >> $output
"`nOMA-URI Path for Intune: $OMA_URI" >> $output
"`nEncrypted Cert Content (line breaks in Notepad - copy all from 'MII', including trailing '=='):`n`n$certContent" >> $output
"`n`n--------END OUTPUT-----------" >> $output
Invoke-Item $output