Unable to connect to Microsoftgraph across tenants using clinet secret in Azure automation runbook
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.