An Easier way to access your Office 365 Cmdlets for Exchange

People that are really big and into Windows PowerShell know all about Implicit Remoting.    It’s a way to access Cmdlets from a Remote server and use them as if they are local.

For those of you just learning PowerShell, I’ll show you something to make that process a LITTLE bit smoother and easier.

 

When you are managing Exchange in Office 365 you normally end up using a process that contains these lines.

 

$Credentials=Get-Credential

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

 

This process will popup a box on your screen prompting for your credentials, think about it for a bit and then eventually give you access to the Cmdlets.   But we can streamline this.   First let’s note something.  Every single time you execute the Import-PSSession it’s going to download those Cmdlets and spin up a temporary copy.    

If you would like a “cached” copy to make your life easier change this line

 

Import-PSSession $Session

 

To read as this line

 

Export-PSSession $Session –outputmodule o365

 

This will take about the same amount of time as the first run but it will create a locally cached module containing all of those redirected Cmdlets

 

Now that you’ve done this, when you have to Manage the Exchange component of your Office 365 environment you can run this Cmdlet.

 

Import-Module o365

 

Running a Cmdlet will prompt with the credentials used to create the module.     If you’d like to make this more portable, just go in the PSM1 file located under the O365 folder created by the module.   By default this will probably be sitting under the Windows PowerShell folder within Documents under your profile.  

If you’d like the path to it programmatically in Windows PowerShell that should be.

 

“$HOMEDocumentsWindowsPowerShellModules”

 

Open up the file callled “o365.psm1” in your favorite text editor

 

image

 

Just do a search for the userid in this file

image

and change it with a blank or even a generic one for technicians to replace with.   It can even be words as it’s just part of a popup box for credentials

image

Just save this file.   You can now take that O365 folder structure, zip it up and distribute it to those that need to Manage Office 365 users.     You should also find it’s a bit faster on startup since you don’t need to re-load the Cmdlets from the cloud each and every time.

 

Occasionally Microsoft may update the Cmdlets on the Exchange side and you might have to redo this process but as you can see all of this is a scriptable and automatable process.  You can rebuild the module at any time.

Leave a Reply