Run Schedule Task that Connects to Graph

rr-4098 1,701 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://zcusa.951200.xyz/en-us/powershell/exchange/app-only-auth-powershell-v2?view=exchange-ps

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,751 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,598 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,802 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kavya 0 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/


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.