PowerShell Exchange Online 365 List S/MIME Certificate Expiration Date

580 Views Asked by At

Is there a command to query the Exchange Online server to get a list of users and the expiration date of their S/MIME certificate?

PS C:\WINDOWS\system32> Import-Module ExchangeOnlineManagement
PS C:\WINDOWS\system32> Connect-ExchangeOnline -UserPrincipalName [email protected]
PS C:\WINDOWS\system32> Get-Mailbox -SortBy Name | select Name,UserSMimeCertificate,UserCertificate

This lists the usernames and their S/MIME certificate. I need also the expiration date of their S/MIME certificate.

Thanks

1

There are 1 best solutions below

0
kavyaS On

I tried to reproduce the same in my environment.

Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName  [email protected]

Check the below way :

 Get-Mailbox -SortBy Name | select Name,UserSMimeCertificate,UserCertificate,Issuer, NotAfter, Subject, FriendlyName | FL

Also check boolean - Return true/false on property value in PowerShell, not the value - Stack Overflow

enter image description here

I donot have certifictaes for users and are empty.

or check like.

$certificateproperties=Get-Mailbox -SortBy Name | select Name,UserSMimeCertificate,UserCertificate | FL

Foreach($user in $certificateproperties.Name )
{

Write-Host  $user
Get-ExchangeCertificate -Thumbprint <usercertthumbprint> | Format-List
}

place $usercertificate.thumbprint for its -Thumbprint

Where format list gives properties like NotAfter which is the expiration of certificate according to get-exchangecertificate description