Forum Discussion
NishaBlue1325
Nov 07, 2023Copper Contributor
PowerShell - how to pass sign-in credentials?
We have been trying to automate MFA in the background, without a user to sign in using the following command: Import-Module -Name Microsoft.Graph.Identity.SignIns
Connect-MgGraph -Scopes "User.R...
VasilMichev
MVP
Refer to this article for the available options for non-interactive use of Connect-MGGraph: https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0
NishaBlue1325
Nov 07, 2023Copper Contributor
VasilMichev Thanks for including the article link. I tried using the client secret:
But it prompts for the client secret. So, the only way to do this without any interaction is using client credential with a certificate?
- LainRobertsonNov 07, 2023Silver Contributor
Hi, Nisha.
The example you've copied and pasted won't work as-is. The example itself even mentions you will be prompted.
That said, when done properly, using a client secret will not prompt, meaning you do not have to use certificate-based authentication (though I'd recommend doing so if you can).
Example
$AppId = <appId of your servicePrincipal>; $Secret = ConvertTo-SecureString -String "<secret from your servicePrincipal>" -AsPlainText -Force; $Credential = [System.Management.Automation.PSCredential]::new($AppId, $Secret); Connect-MgGraph -TenantId <yourOrganisation.onmicrosoft.com> -ClientSecretCredential $Credential;
Note: You should never leave a password or secret in your script. This example is purely for demonstration purposes only.
Cheers,
Lain