I referred this link and it explain how to connect using client and secret.
But, I cannot use this in production environment as the PowerShell script is going to store in the server. Anyone can open it and see the creds.
Could you please kindly explain me how to use a certificate instead of client and secret to connect Azure AD and extract users last log in information without any user interaction or MFA prompts with pop-up windows.
Thanks
2
Answers
A common approach to this problem would be to fetch the secret from a key management solution such as Azure KeyVault. You can store the client secret in Azure KeyVault and fetch it from server using Managed Identity. A step-by-step guide can be found here.
Initially, I created one self-signed certificate from PowerShell using below script:
Response:
Now, I uploaded this certificate to my app registration in Entra ID like this:
To connect to Microsoft Graph as a service principal with certificate, you can make use of below PowerShell script that does not involve any user interaction:
Response:
Now, I ran below PowerShell script and got last log in date time of users successfully in response without any pop-up window:
Response:
Reference:
Using Microsoft Graph PowerShell authentication commands | Microsoft