PowerShell Basics for Office 365 Administration (Episode 2)

To effectively manage your Office 365 environment using PowerShell, installing the appropriate modules is a prerequisite. The most frequently used modules for this purpose include:

  • Microsoft Graph: The recommended and modern module for interacting with Microsoft 365 services through the unified Graph API.
  • Exchange Online Management: Essential for administering Exchange Online mailboxes, policies, and settings.
  • Microsoft SharePoint Online: Modules for managing SharePoint Online sites, lists, and permissions. The PnP.PowerShell module is widely used for modern SharePoint Online and OneDrive management.
  • Microsoft Teams: For administering Microsoft Teams settings, users, and teams.
  • MSOnline: An older module still used for certain licensing and directory management tasks, though being superseded by Microsoft Graph.
  • AzureAD: Another legacy module for managing Azure Active Directory objects, also being replaced by Microsoft Graph.

Below are the steps to install these key modules. The -Force parameter is included to overwrite any existing versions during installation.

Module Installation Steps

  1. Install the Exchange Online PowerShell V3 Module: This module is crucial for managing Exchange Online and supports modern authentication methods.

    Install-Module ExchangeOnlineManagement -Force
    
  2. Install the Microsoft Graph Module: As the central API for Microsoft 365 services, the Microsoft Graph module is increasingly important for modern automation.

    Install-Module Microsoft.Graph -Force
    

    Alternatively, you can install specific sub-modules if you only need to manage certain aspects (like users):

    Install-Module Microsoft.Graph.Users
    
  3. Install the MSOnline Module (Legacy): While being phased out, this module is still necessary for specific functions like managing licenses and interacting with older scripts.

    Install-Module MSOnline -Force
    
  4. Install the AzureAD Module (Legacy): This module is used for managing Azure AD objects but is also being superseded by the Microsoft Graph module.

    Install-Module AzureAD -Force
    

Note: Microsoft strongly advises migrating to the Microsoft Graph module for future development and automation, as the MSOnline and AzureAD modules are scheduled for deprecation. More information can be found here: Action required: MSOnline and AzureAD PowerShell retirement - 2025 info and resources

Other valuable modules for Office 365 administration include Microsoft.Online.SharePoint.PowerShell, SharePointPnPPowerShellOnline, and MicrosoftTeams. Install these using the same Install-Module command as needed.

Updating Modules

To ensure you have the latest features and bug fixes, regularly update your installed modules. You can update all modules with the following command:

Update-Module -Force

First-Time Setup Notes

If this is your first time installing modules from the PowerShell Gallery, you might be prompted to install the NuGet package provider or trust the PSGallery repository. You can proactively handle these by running:

Install-PackageProvider NuGet -Force
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

Further details on setting up your environment can be found here: Install-Module

Connecting to Office 365 Services

Once the necessary modules are installed, the next step is to import them into your current PowerShell session and establish a connection to the respective services.

  1. Exchange Online:

    Import-Module ExchangeOnlineManagement
    Connect-ExchangeOnline
    

    This command will typically open an interactive sign-in window that supports Multi-Factor Authentication (MFA).

  2. Microsoft Graph: Connecting with the Microsoft Graph module has a slightly different workflow, often involving specifying required permissions (scopes).

    Import-Module Microsoft.Graph
    Connect-MgGraph
    

    To connect with specific permissions, use the -Scopes parameter:

    Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
    
  3. MSOnline (Legacy Connection): For tasks requiring the MSOnline module:

    Import-Module MSOnline
    Connect-MsolService
    
  4. AzureAD (Legacy Connection): For tasks requiring the AzureAD module:

    Import-Module AzureAD
    Connect-AzureAD
    

By following these steps, you can set up your PowerShell environment to connect to and manage your Office 365 services effectively. Remember to prioritize using the Microsoft Graph and Exchange Online Management modules for modern automation tasks.

Comments

Popular posts from this blog

Microsoft 365 Office Update Channels: A Complete Guide

Unveiling Primary Mailbox Statistics

Manage DL Members in OWA Without Allowing DL Creation – A Practical Solution