2
votes

I have a load of Azure Powershell deployment scripts that are triggered by the build server after the completion of a build which work perfectly - I use the Import-AzurePublishSettingsFile (which is securely stored locally) to log into Azure unattended.

I now need to extend these to include management of Sql Azure Servers, Elastic Pools and Databases.

These, however, are part of the Azure Resource Manager cmdlets which have a different method of authentication.

I've found these articles:

but all appear to require you to enter your credentials at some stage at the process. The second link above explicitly states:

The AzureResourceManager module requires Add-AzureAccount. A Publish Settings file is not sufficient.

I've tried (just to see what happens) switching to the Resource Manager with Switch-AzureMode -Name AzureResourceManager and then just executing one of the cmdlets, such as Get-AzureResourceGroup -Name "blah" but I just get an error of

Get-AzureResourceGroup : AuthenticationFailed: Authentication failed. The 'Authorization' header is not present or provided in an invalid format.

I am quite happy to set up an AD Application, manually, once, through the portal and then provide my scripts with the relevant Application ID or whatever is required. I just need it to be unattended so that my build can deploy!

Can anyone tell me how I go about making an unattended script to use these Azure Resource Manager cmdlets through Powershell?

1
I think I may have found the answer... blogs.msdn.com/b/tomholl/archive/2014/11/25/…oatsoda

1 Answers

1
votes

This post gives full details of how to do this. Basically you embed your powershell scripts with the username and password of your AD user.

But be aware that if, like me, you wish to combine calls to the AzureResourceManager and AzureServiceManagement modes (using Switch-AzureMode) then you must use Add-AzureAccount -Credential <credentials> and also Remove-AzureAccount -Name <username> otherwise some of the AzureServiceManagement mode cmdlets cease to work.