Azure Powershell Part 1-Setup and Start
Using Powershell in Azure is a powerful and quick way to script and automate frequent coming tasks. starting with Azure Powershell there some pre-requisites, I won’t go into much details here but basically how to load / install the Azure Powershell module can be found here
Once you successfully installed Azure Powershell on your machine you can do have a bunch of new commands available
To get a better overview of all commandlets related to a specific module you can use a.e. Get-Command -Module Azure
Now we have to connect to Azure and set up subscription data so we have a connection to Azure
Step 1: Add your account
1.At the PowerShell prompt, type Add-AzureAccount and click Enter.
2.Type in the email address associated with your Azure subscription and click Continue.
3.Type in the password for your account.
4.Click Sign in.
you can do this interactively or you can script that
$cred = Get-Credential
Add-AzureAccount -Credential $cred
or to automate this in a script to avoid pop-up you can also use
$userName = "<your organizational account user name>" $securePassword = ConvertTo-SecureString -String "<your organizational account password>" -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential($userName, $securePassword) Add-AzureAccount -Credential $cred
Note: take security considerations into account when hard coding service accounts / passwords. consider decrypt/encrypt password in your scrip runtime
Step 2: Set your subscription and storage account
Set your Azure subscription and storage account by running these commands at the Windows PowerShell command prompt. Replace everything within the quotes, including the < and > characters, with the correct names.
$subscr="<subscription name>" $staccount="<storage account name>" Select-AzureSubscription -SubscriptionName $subscr –Current Set-AzureSubscription -SubscriptionName $subscr -CurrentStorageAccountName $staccount
You can get the correct subscription name from the SubscriptionName property of the output of the Get-AzureSubscription command. You can get the correct storage account name from the Label property of the output of the Get-AzureStorageAccount command after you run the Select-AzureSubscription command