Saturday, March 31, 2018

Setting up powershell for microsoft azure cloud

So it is that time of the day, actually night, actually morning 2:15am where I felt like trying out of azure. I most prefer to learn by seeing and doing but i like my words, thank you very much. The way you do with words (command prompt, script, automation) remains same, similar and sometimes identical forever but GUI keeps changing.
Run your powershell 5, 6 or ISE, whichever you like; even your visual studio code if it is configured with powershell.
Install-Module -Name AzureRM -AllowClobber

I also suggest you to go ahead and get the cli tool for powershell from here
close all the powershell windows.
launch the powershell as administrator and enable execution of script by running the following.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Now we want to get the azure credentials.
Get-AzurePublishSettingsFile
It takes you to the azure portal where you can select the payment model, validate and for that you get to download publish settings.
Now we will import them using the downloaded file and delete that file. Once imported that file is no more needed (for security reasons).

PS C:\Users\<username>> Import-AzurePublishSettingsFile 'C:\Users\<username>\Documents\azure\Windows Azure MSDN - 1_4_2018, 04_43_29 - credentials.publishsettings'

Id                                   Name          State ExtendedProperties                        
--                                   ----          ----- ------------------                        
f6ec6bf5-7459-46f5-a274-5a44c60fef0a Pay-As-You-Go       {[Account, 411690FA9A067441A00E1DDBECD7...
Now let us whether it worked by trying to list all the azure environments.

PS C:\Users\<username> Get-AzureEnvironment


Name                                     : AzureGermanCloud
EnableAdfsAuthentication                 : False
ActiveDirectoryServiceEndpointResourceId : https://management.core.cloudapi.de/
AdTenant                                 : Common
GalleryUrl                               : https://gallery.azure.com/
ManagementPortalUrl                      : http://portal.microsoftazure.de/
ServiceManagementUrl                     : https://management.core.cloudapi.de/
PublishSettingsFileUrl                   : https://manage.microsoftazure.de/publishsettings/index
ResourceManagerUrl                       : https://management.microsoftazure.de/
SqlDatabaseDnsSuffix                     : .database.cloudapi.de
StorageEndpointSuffix                    : core.cloudapi.de
ActiveDirectoryAuthority                 : https://login.microsoftonline.de/
GraphUrl                                 : https://graph.cloudapi.de/
TrafficManagerDnsSuffix                  : azuretrafficmanager.de
AzureKeyVaultDnsSuffix                   : vault.microsoftazure.de
AzureKeyVaultServiceEndpointResourceId   : https://vault.microsoftazure.de

Name                                     : AzureCloud
EnableAdfsAuthentication                 : False
ActiveDirectoryServiceEndpointResourceId : https://management.core.windows.net/
AdTenant                                 : Common
GalleryUrl                               : https://gallery.azure.com/
ManagementPortalUrl                      : http://go.microsoft.com/fwlink/?LinkId=254433
ServiceManagementUrl                     : https://management.core.windows.net/
PublishSettingsFileUrl                   : http://go.microsoft.com/fwlink/?LinkID=301775
ResourceManagerUrl                       : https://management.azure.com/
SqlDatabaseDnsSuffix                     : .database.windows.net
StorageEndpointSuffix                    : core.windows.net
ActiveDirectoryAuthority                 : https://login.microsoftonline.com/
GraphUrl                                 : https://graph.windows.net/
TrafficManagerDnsSuffix                  : trafficmanager.net
AzureKeyVaultDnsSuffix                   : vault.azure.net
AzureKeyVaultServiceEndpointResourceId   : https://vault.azure.net

Name                                     : AzureUSGovernment
EnableAdfsAuthentication                 : False
ActiveDirectoryServiceEndpointResourceId : https://management.core.usgovcloudapi.net/
AdTenant                                 : Common
GalleryUrl                               : https://gallery.azure.com/
ManagementPortalUrl                      : https://manage.windowsazure.us
ServiceManagementUrl                     : https://management.core.usgovcloudapi.net/
PublishSettingsFileUrl                   : https://manage.windowsazure.us/publishsettings/index
ResourceManagerUrl                       : https://management.usgovcloudapi.net/
SqlDatabaseDnsSuffix                     : .database.usgovcloudapi.net
StorageEndpointSuffix                    : core.usgovcloudapi.net
ActiveDirectoryAuthority                 : https://login.microsoftonline.us/
GraphUrl                                 : https://graph.windows.net/
TrafficManagerDnsSuffix                  : usgovtrafficmanager.net
AzureKeyVaultDnsSuffix                   : vault.usgovcloudapi.net
AzureKeyVaultServiceEndpointResourceId   : https://vault.usgovcloudapi.net

Name                                     : AzureChinaCloud
EnableAdfsAuthentication                 : False
ActiveDirectoryServiceEndpointResourceId : https://management.core.chinacloudapi.cn/
AdTenant                                 : Common
GalleryUrl                               : https://gallery.azure.com/
ManagementPortalUrl                      : http://go.microsoft.com/fwlink/?LinkId=301902
ServiceManagementUrl                     : https://management.core.chinacloudapi.cn/
PublishSettingsFileUrl                   : http://go.microsoft.com/fwlink/?LinkID=301776
ResourceManagerUrl                       : https://management.chinacloudapi.cn/
SqlDatabaseDnsSuffix                     : .database.chinacloudapi.cn
StorageEndpointSuffix                    : core.chinacloudapi.cn
ActiveDirectoryAuthority                 : https://login.chinacloudapi.cn/
GraphUrl                                 : https://graph.chinacloudapi.cn/
TrafficManagerDnsSuffix                  : trafficmanager.cn
AzureKeyVaultDnsSuffix                   : vault.azure.cn
AzureKeyVaultServiceEndpointResourceId   : https://vault.azure.cn
and yes it did.