Automating Windows Azure Active Directory Module for Powershell Connections - Office 365

I have been working on a PowerShell script to automated the Windows Azure Active Directory Module for Powershell Connection and login. 

I started by exporting my password to a file so that powershell could load that from my script.

 (get-credential).password|convertFrom-SecureString|set-content c:\cred.txt  

Then I created this powershell script to make the connection.  At the bottom I added some powershell to tell us when the last DirSync was run too.  This is set to utc by default, so I also convert that to Local Time.

 $pass = get-content C:\cred.txt | convertto-securestring
 $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "",$pass
 $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $cred -Authentication:Basic -AllowRedirection
 Import-PSSession $Session | Out-String
 Connect-MsolService -Credential $cred | Out-String
 echo "Last Dir Sync Completed at:"
 $DATEutc = Get-MSOLCompanyInformation | select -expand LastDir* 


Popular posts from this blog

Add your Office 2016 KMS Keys to your Volume Activation Server

Solving WinRM Host connection errors in SCVMM - System Center Virtual Machine Manager 2012 R2

Adding Windows 10 to your Server 2012 R2 KMS Server