Category: Office365


Connect to Azure/Office365 based on encrypted txt file


This will create a remote PowerShell session to your Azure/Office365 based on the Username you specify and the #hashed password text file you created in the previous​ post (that you can find here)
#==============================================================================================
# NAME: Connect to Azure/Office365
# AUTHOR: Vincent Christiansen, vincent@sameie.com
# DATE  : 21/01/2016
# COMMENT: This script will create a remote session in Azure/Office365 based on the encrypted file you have created.
#
# ​​=============================================================================================
$username = “YourServiceAccount@YOURDOMAIN.onmicrosoft.com”
$encrypted = Get-Content “D:\Scripts\Azure_Encrypted_Password.txt” | ConvertTo-SecureString
$cred = New-Object System.Management.Automation.PsCredential($username,$encrypted)
Import-Module MSOnline
Connect-MsolService -Credential $cred
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxymethod=rps -Credential $cred -Authentication Basic -AllowRedirection
$importresults = Import-PSSession $ExchangeSession

Select Azure Subscription to work with


When you have a larger organisation, you will have several Azure Subscriptions to work against. So here is how you switch.

1. Open Powershell

2. Type in: Add-AzureRmAccount​
(in pop-up enter admin id and password)

3. It will list up the subscription you are connected to when you have authenticated


4. Type in: Get-AzureRmSubscription
(will list out all your subscriptions)

5. Find the Subscription you want to connect to

6. Type in: Select-AzureRmSubscription -SubscriptionId “ENTER THE SUBSCRIPTION ID”

You can choose SubscriptionName too, but I prefere SubscriptionID