Skip to content

Instantly share code, notes, and snippets.

@jtlimson
Created June 16, 2020 02:52
Show Gist options
  • Save jtlimson/918c464823ea61c54439f9b237c8d3a1 to your computer and use it in GitHub Desktop.
Save jtlimson/918c464823ea61c54439f9b237c8d3a1 to your computer and use it in GitHub Desktop.

Password-based authentication

To get the service principal's credentials as the appropriate object, use the Get-Credential cmdlet. This cmdlet will present a prompt for a username and password. Use the service principal ID for the username.

$pscredential = Get-Credential
Connect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $tenantId

For automation scenarios, you need to create credentials from a user name and secure string:

$passwd = ConvertTo-SecureString <use a secure password here> -AsPlainText -Force
$pscredential = New-Object System.Management.Automation.PSCredential('service principal name/id', $passwd)
Connect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $tenantId

Certificate-based authentication

Certificate-based authentication requires that Azure PowerShell can retrieve information from a local certificate store based on a certificate thumbprint.

Connect-AzAccount -ApplicationId $appId -Tenant $tenantId -CertificateThumbprint <thumbprint>

When using a service principal instead of a registered application, add the -ServicePrincipal argument and provide the service principal's Application ID as the -ApplicationId parameter's value.

Connect-AzAccount -ServicePrincipal -ApplicationId $servicePrincipalId -Tenant $tenantId -CertificateThumbprint <thumbprint>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment