Connecting Exchange Online via Powershell

Hi All,

I got Office 365 Trial as a part of MVP from Microsoft so I started exploring it for myself & others as many companies are either evaluating or moving towards this SAS model.

First experience is that it is too simple for administration but still there are many things that you need to do where PowerShell will be handy.

As majority of the time I work on Exchange, I started first exploring connecting to Exchange online via PowerShell, I don’t want to enter long commands each time.

Here is what I have done , written two small functions below (which can be downloaded from here as well) and imported in power-shell profile so that when you launch PowerShell you just have to type LaunchO365 and when your work is completed, you just need to type RemoveO365.( Removing of session is important as there is a limit on number of open sessions)

You can change the name of the functions to whatever you like, such as LaunchExOnline and RemoveExOnline to make it more relevant.

#############################################################

Function LaunchO365 {

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

}

##############################################################

Function RemoveO365 {

$Session = Get-PSSession | where {$_.ComputerName -like “outlook.office365.com”}
Remove-PSSession $Session

}

##############################################################

How to import these functions in your profile to load them each time?

Open Power-shell & if you have not created your profile run the following command to get it created, if you already have a power-shell profile than skip to next step.

New-Item -ItemType File -Path $profile -Force

Capture

Now run below command to open the profile in Notepad.

notepad $profile

Copy the functions in the notepad & save it

Capture1

Now every-time when you will launch power-shell you just need to type below:

LaunchO365

Capture2

Run the commands/ do your work

Capture

RemoveO365 (to remove the session)

Capture

I like the things to be made easy so if you think the same, use above technique & save your 5 -10 mins 🙂

 

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

 

 

 

Advertisement

2 thoughts on “Connecting Exchange Online via Powershell

  1. Pingback: How to Track Message in Office 365 | Microsoft Technologies Blog

  2. Pingback: How to Track Message in Office 365 | Tech Wizard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s