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