On rare occasions, you may sometimes need to log in with an Azure service principal. Below is a code snippet that you can use to authenticate as a service principal. You will need to know the client ID and either know a client secret that has been generated or have access to a client certificate.
Once signed in, you are that service principal. So running commands like Get-AzSubscription or Get-AzResourceGroup may help with identifying role-based access control issues.
Login As Service Principal with Secret
PowerShell
Reference: MS Learn - Connect to Azure using a service principal account
This snippet is really here because I forget how to generate the $Credential object everytime I need to do this!
| |
