Run Schedule Task that Connects to Graph

rr-4098 2,051 Reputation points
2025-01-10T20:52:51.7866667+00:00

I need to create a Scheduled Task that will run a Powershell script that connects to Graph. What is the best way to setup the task so the creds are passed and it can log into Graph unattended. I have read some have created an App for this in Entra but I never did that before.

https://learn.microsoft.com/en-us/powershell/exchange/app-only-auth-powershell-v2?view=exchange-ps

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Kavya 490 Reputation points
    2025-01-11T13:05:07.0266667+00:00

    Yes. You can register an app in Entra and use certificate-based authentication to connect to Microsoft Graph. When scheduling, you can pass the app ID, tenant ID, and certificate thumbprint. It's secure too.

    If you don't prefer CA certificates, you can easily create self-signed certificate using PowerShell. (preferred for internal and testing purpose only).

    $Certificate=New-SelfSignedCertificate -Subject testing.com -CertStoreLocation Cert:\CurrentUser\My

    After creation, you can export the certificate to the preferred path.
    Export-Certificate -Cert $Certificate -FilePath "C:\$certname.cer"

    You can refer to this resource for a detailed, step-by-step guide—from registering an app to creating a self-signed certificate and using it to connect to Microsoft Graph for running unattended scripts: https://blog.admindroid.com/connect-to-microsoft-graph-powershell-using-certificate/


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.