Skip to content

Instantly share code, notes, and snippets.

@scusi
Last active February 1, 2024 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scusi/9f15ab9ac54c0f515819387a64b788c2 to your computer and use it in GitHub Desktop.
Save scusi/9f15ab9ac54c0f515819387a64b788c2 to your computer and use it in GitHub Desktop.
Publishing a Certificate in GAL useing powershell
# Source: https://techcommunity.microsoft.com/t5/exchange/upload-s-mime-user-certificate-with-outlook-to-the-gal/m-p/3781147
#
# i do not know if this code works, never tried.
# i just wanted to keep it, just in case or to try it one day.
# Even if it does not work, it might be a good starting point.
# ~scusi
###############################################################################
#Set UserCertificate in EXO
###############################################################################
Connect-ExchangeOnline
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("D:\temp\a.bohren@icewolf.ch_swisssign.cer")
$certArray = New-Object System.Collections.ArrayList
$certArray.Insert(0,$cert.GetRawCertData())
Set-Mailbox -Identity email address removed for privacy reasons -UserCertificate $certArray
$MBX = Get-RemoteMailbox -Identity email address removed for privacy reasons
$Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($mbx.UserCertificate)
$Cert | fL
###############################################################################
#AD
###############################################################################
$ADUser = Get-ADUser -Identity "a.bohren" -Properties userCertificate
$ADUser.userCertificate
$Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($ADUser.userCertificate)
$Cert | fL
Set-ADUser -Identity "a.bohren" -Clear "userCertificate"
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("D:\temp\a.bohren@icewolf.ch_swisssign.cer")
Set-ADUser -Identity "a.bohren" -add @{"userCertificate"=$Cert.Rawdata}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment