In order for this setup to work you must be an administrator for your azure subscription:
- Create a new application registration under Azure Active Directory.
- Generate a key for the application.
- Assign the application to your azure subscription(s).
The community has put together an excellent how to document which will walk you though the 3 steps mentioned above, this can be found at https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal
After performing all 3 steps, you should gather the following information:
- Tenant ID/Directory ID: This is found under the Properties blade of the Azure Active Directory
- Application ID: This is found under the Properties blade of the Register application
- Secure Key: This is found and generated under the Keys blade of the Register application
After you’ve gather all the information, plug it into this script and execute it. I’ve tested this on Azure Powershell version 4.0.2. To get your version of Azure Powershell execute the following:
Get-Module -ListAvailable -Name Azure -Refresh | Select Version
Here is the script to authenticate your service principal:
$key = '' # Found under Azure AD -> Application -> Keys $applicationId = '' # Application ID - Self explanatory $tenantId = '' # This ID is found under Properties for the Azure Active Directory # Create credentials $pass = ConvertTo-SecureString $($key) -AsPlainText -Force $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $applicationId, $pass # Authenticate Login-AzureRmAccount -Credential $cred -ServicePrincipal -TenantId $tenantId