The Most Useful PowerShell Commands for Office 365 Exchange Online

Before connecting the Office 365 to the Windows PowerShell we need to give and install following required permissions:

  1. First, we need to provide a Global Admin Role to that O365 account.
  2. Microsoft.Net Framework 4.5 and Windows Management Framework 4.0 or any latest version should be installed.
  3. Now download and install PowerShell modules of office 365 and its services like Skype for business.
  • Microsoft Online Services Sign-In Assistant for IT Professionals RTW
  • Skype for Business Online, Windows PowerShell Module
  • Windows Azure Active Directory Tool

Connect Office 365 with the PowerShell Commands

For connecting the o365 Cloud Platform to the Windows PowerShell follow all the steps.

Step 1: First open the installed Azure Active Directory and import the online services of Active Directory & Office 365 for PowerShell Modules.

Install-Module –Name AzureAD

Install-Module –Name MSOnline

Step 2: Now open the Windows PowerShell and log in the Exchange Online administrator account in Windows PowerShell.

$Credential = Get-Credential

Step 3: After that create the Remote session

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

Step 4: Import the Session

Import-PSSession $O365

Step 5: Connect the Office 365 services with PowerShell

Connect-MsolService –Credential $O365

Now we are ready to navigate or manage our Exchange Online Account by the PowerShell Commands.

Connect the SharePoint with the PowerShell Command

Step 1: We can also connect the SharePoint and Exchange Online by putting the following commands

$Cred = Get-Credential

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

Step 2: After that, you need to install the SharePoint Online Management Shell and then run the given commands.

$admin="[email protected]"

$orgname="enterprise"

$userCred = Get-Credential -UserName $admin -Message "Type the password."

Connect-SPOService -Url https://$orgname-admin.sharepoint.com -Credential $userCred

Get the cmdlets of available Exchange Online PowerShell Commands.

For knowing the list of available o365 PowerShell by putting:

Get-Command -module MSOnline

Here you can also check the Azure Active Directory command list by typing the following command.

Get-Command -module AzureAD

Know the list of all office 365 Users with the Windows PowerShell

If you want to know the lists of all Office 365 Users Mailbox then use the Get-MsolUser command. For showing the DisplayName, City, Department, and ObjectID Parameters type the below command.

Get-MsolUser | Select DisplayName, City, Department, ObjectID

To know the number of licenses:

Get-MsolAccountSku

For the available services type:

Get-MsolAccountSku | select -ExpandProperty ServiceStatus

10pshcmdletsoffice365i2

Create a New Exchange Online User Using PowerShell

You can create a New User of the Office 365 Exchange Online with the PowerShell by putting the following command.

New-MsolUser -UserPrincipalName [email protected] -DisplayName "Pankaj Kumar" -FirstName “Pankaj” -LastName “Kumar”

Remove the user of Office 365 list by PowerShell

Here you can also remove or delete an Office 365 User from a list.

Get-SPOSite | ForEach {Remove-SPOUser -Site $_.Url -LoginName “[email protected]"}

Change o365 Password using PowerShell

If you want to change the Password of Exchange Online by PowerShell Command then type the following command.

Set-MsolUserPassword -UserPrincipalName [email protected] -NewPassword P@SSw0rd!

Conclusion: In this article, I explain the most useful Office 365 Exchange Online PowerShell. So follow all the step by step solution for connecting o365 with PowerShell. If you still have any doubt just leave a message on the comment box.

3 thoughts on “The Most Useful PowerShell Commands for Office 365 Exchange Online

  1. Pingback: How to enable or disable In-Place Archive Mailbox in Office 365 Account

  2. Pingback: How to increase Microsoft Office 365 Exchange Online Mailbox size

  3. Pingback: How to set-up the Application Impersonation rights in Office 365

Leave a Reply

Your email address will not be published. Required fields are marked *