# Connect-MgGraph: Keyset does not exist

I had this little issue today when I tried to schedule the Microsoft Graph script to run as a service account on a certificate. To my surprise, even tho I had all permissions required, I was getting this error message: Connect-MgGraph: Keyset does not exist. Something that didn’t show up for my user.

blog

20 Jul 2023 pl

![Connect-MgGraph: Keyset does not exist](/wp-content/uploads/2023/07/Microsoft-Graph-API.png)

[Zobacz obrazy (3)](#pf-content-image-1-0)

I had this little issue today when I tried to schedule the Microsoft Graph script to run as a service account on a certificate. To my surprise, even tho I had all permissions required, I was getting this error message: **Connect-MgGraph: Keyset does not exist**. Something that didn't show up for my user.

[!\[Blad zadania PowerShell pokazujacy, ze Connect-MgGraph konczy sie komunikatem Keyset does not exist\](/wp-content/uploads/2023/07/img_64b7a2ae8d8dd.png)](/wp-content/uploads/2023/07/img_64b7a2ae8d8dd.png)

The message indicated my process has difficulty reaching the key of my chosen certificate. Trying to run the scheduled task with the highest privileges didn't change anything. Since **Connect-MGGraph** doesn't support PFX files, you must upload the certificate to the **Local Machine store** and refer to it via **Thumbprint**.

### 💡 Fixing Connect-MgGraph: Keyset does not exist

When using **certificates as a standard user,** I usually do it in the following way:

```powershell
Connect-MgGraph -CertificateThumbprint '9135E5CF311C051A' -ClientId 'a7b8a419' -TenantId '5e94ad53'
```

The problem is – it only works for certificates in the user store. When you switch to **Local Machine Store**, **Connect-MGGraph** no longer sees the certificate, so you need to change to a different connection method.

```powershell
$Thumbprint = '9135E5CF'
$LocalMachineCert = Get-ChildItem -Path Cert:\LocalMachine -Recurse | Where-Object { $_.Thumbprint -eq $Thumbprint }
Connect-MgGraph -ClientId 'a7b8a419' -TenantId '5e94ad53' -Certificate $LocalMachineCert
```

This way, we tell **Connect-MgGaph** to use the **LocalMachine** Certificate store, but while it worked for me when testing it using my account, things were not so great when trying it as a service account. Fortunately, there's an easy fix for that. We need to allow that particular service account access to private keys for that specific certificate.

[!\[Okno uprawnien klucza prywatnego certyfikatu, w ktorym konto uslugi otrzymuje dostep dla Connect-MgGraph\](/wp-content/uploads/2023/07/img_64b7b44f1057e.png)](/wp-content/uploads/2023/07/img_64b7b44f1057e.png)

Add a missing service account with proper permissions, and you're ready!

[!\[Okno uprawnien certyfikatu pokazujace dodane konto uslugi z dostepem do klucza prywatnego\](/wp-content/uploads/2023/07/img_64b7b47b6fc39.png)](/wp-content/uploads/2023/07/img_64b7b47b6fc39.png)

Of course, you need to do it on your proper certificate, not the Razer Chroma SDK certificate, as shown in the screenshot.

## Powiązane projekty

Projekty powiązane z tagami, kategoriami i treścią tego wpisu.

[Wszystkie projekty](/projekty/)

Trwa dopasowywanie projektów...

[Powrót do bloga](/blog/)

## Powiązane wpisy

- [Check an API write after a PowerShell timeout](/blog/verify-uncertain-api-outcomes-powershell/)
- [Inspect and convert mixed Office archives with PSWriteOffice](/blog/inspect-and-convert-mixed-office-archives-pswriteoffice/)
- [Compose PDF reports and automate page workflows with PSWriteOffice](/blog/automate-pdf-reports-and-page-workflows-pswriteoffice/)

<!-- PowerForge markdown artifact sha256:8D5AA11A13487DA7BEED4EAB72CABB46D7799BFCF0B614F5567A8FBE70965055 -->
