Troubleshooting
PowerShell
Keyset Does Not Exist Error When Connecting to Exchange Online via PowerShell
7 min
issue summary when attempting to connect to exchange online using powershell, users may encounter the following error keyset does not exist this error typically occurs when the certificate used for authentication is missing its private key or is improperly configured reproduction the error can be reproduced using a c# script that attempts to access the private key of a certificate stored in the localmachine\my store here's a simplified version of the script using system; using system security cryptography x509certificates; class script { public void main() { string thumbprint = "your thumbprint"; // replace with actual thumbprint x509store store = new x509store(storename my, storelocation localmachine); try { store open(openflags readonly); var certcollection = store certificates find( x509findtype findbythumbprint, thumbprint, validonly false ); if (certcollection count > 0) { var cert = certcollection\[0]; console writeline($"certificate found {cert subject}, has private key {cert hasprivatekey}"); var privatekey = cert privatekey; // error occurs here } else { console writeline("certificate not found in localmachine\my store "); } } finally { store close(); } } } root cause the error is triggered when the certificate does not have an accessible private key this can happen due to the certificate being imported without its private key incorrect permissions on the private key the certificate being corrupted or improperly generated suggested resolution steps reimport the certificate with private key ensure the certificate is imported into the localmachine\my store with its private key use the pfx file format which includes the private key generate a new certificate if reimporting fails, generate a new certificate import it into the localmachine\my store upload the new certificate to the azure application associated with exchange online stack trace overview the error manifests during the execution of the connect exchangeonline command connect exchangeonline skiploadingformatdata $true appid '\<appid>' organization '\<org> onmicrosoft com' certificatethumbprint '\<thumbprint>' exception details system security cryptography cryptographicexception keyset does not exist occurs during certificate private key access and token signing operations resolution we ended up resolving this by granting rights to manage the private key in the certificate console references microsoft docs connect to exchange online powershell certificate management in windows