Connect to Office 365 with PowerShell

Asked By 10 points N/A Posted on -

I was facing a problem regarding the connection of Office 365 with Powershell. Can you help me with connecting it? Thanks in advance.

Best Answer by Antoine D Hanson
Answered By 0 points N/A #328830

Connect to Office 365 with PowerShell


Hello. I hope you will find this post helpful. So, The web admin interface for Office 365 is very good, but sometimes PowerShell is more suited. Here we will go through every step for connection to Office 365 with PowerShell.

Step 1- Firstly, open the PowerShell session.

Step 2- Now, you have to store your Credentials in a variable:

Step 3- Now enter your Office 365 Credentials when prompted:

Step 4- Create a new PowerShell session from the Office 365 server:


Step 5- Import the session:

Import-PSSession $Session

Step 6- Now, you can run any command you need.

Step 7- When you have finished, remove the session you created in step 2:

Remove-PSSession $Session

*Here is the complete code to connect to Office 365 with PowerShell

$Cred= Get-Credential

$Session= New-PSSession-ConfigurationName

Import-PSSession $Session

#You can run any command you want here

Remove-PSSession $Session

Login/Register to Answer

Related Questions