Nick's Blog

Connect to Azure subscription without using a certificate


This post will demonstrate how to use PowerShell to connect to Azure subscription without using a certificate.

Login to your Azure Portal > Settings > Administrators
You can use an existing account, or create a new one, like below:


And then, create a workflow called Connect-MySubscription, paste the following code into the workflow script block:


1
2
3
4
5
$Cred = Get-AutomationPSCredential -Name 'YourAccountName'

Add-AzureAccount -Credential $Cred

Select-AzureSubscription -SubscriptionName 'Subscription Name'

You can find out your account name under Settings > Administrators > Name, and your subscription name is under Settings > Administrators > Subscriptions > Subscription.

Replace the above value into the script and you are good to go.

To test whether it’s working properly, you can run the script within Azure, and you should see the output like below in the output pane. and the script supposes to have a completed status.

1
2
3
4
5
6
PSComputerName        : localhost
PSSourceJobInstanceId : blablabla-5422-498c-8a43-59blabla0d
Id : YourAccountName
Type : User
Subscriptions : d5601745-f9b0-431c-8bla-b9blablabla09
Tenants : blablab201-918d-4es0-asd4-0fblabla923fc0