Unable to connect to Microsoftgraph across tenants using clinet secret in Azure automation runbook

Shri Gowtham Tharun Reddy Abbireddy 146 Reputation points
2025-03-11T03:30:10.5133333+00:00

I'm trying to connect to microsoft graph using a client secret in an azure automation runbook,but I'm encountering several errors. I am using power shell script, I've tried diiferent ways to login. Below are the different errors:

1)Invalid JWT Access Token:

Connect-MgGraph -ClientId "My Client ID" -clientSecret "MyClientSecret"- TenantId "TargetTenantId"-Scopes "Application.ReadWrite.All"

I have all the modules installed in the runbook.
. Error: Invalid JWT access token. Authentication needed. Please call connect-MgGraph

2)Parameter Binding exception:

$SecureClientSecret = ConvertTo-SecureString -String $ApplicationClientSecret -AsPlainText -Force

$ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ApplicationClientId, $SecureClientSecret

Connect-MgGraph -TenantId $TenantId -ClientSecretCredential $ClientSecretCredential

Error: System.Management.Automation.ParamterBindingException: Cannot bind parameter'ClientSecret Credential'. Cannot convert the "System.Security.SecureString" value of type "System.Security.SecureString" to the "System.Management.Automation.PSCredential".

My script is working fine when I run from my local.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,328 questions
0 comments No comments
{count} vote

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.