Add-Office365Functions.ps1
19 Sep 2025Description
Purpose
Adds Office 365 PowerShell modules to the current session.
Detailed Description
The Add-Office365Functions function is used to import the necessary Office 365 PowerShell modules into the current session. It checks if the modules are already installed and imports them if they are available. If a module is not installed, it installs the module from the PowerShell Gallery.
Usage
Example 1
Add-Office365Functions
This example demonstrates how to use the Add-Office365Functions function to import the Office 365 PowerShell modules into the current session.
Notes
Author: Your Name Date: Current Date
Script
<#
.SYNOPSIS
Adds Office 365 PowerShell modules to the current session.
.DESCRIPTION
The Add-Office365Functions function is used to import the necessary Office 365 PowerShell modules into the current session. It checks if the modules are already installed and imports them if they are available. If a module is not installed, it installs the module from the PowerShell Gallery.
.PARAMETER None
This function does not accept any parameters.
.EXAMPLE
Add-Office365Functions
This example demonstrates how to use the Add-Office365Functions function to import the Office 365 PowerShell modules into the current session.
.NOTES
Author: Your Name
Date: Current Date
#>
function Add-Office365Functions {
$Modules = "AADRM", "AzureAD", "AzureADPreview", "Microsoft.Online.SharePoint.PowerShell", "MicrosoftTeams", "MSOnline", "SharePointPnPPowerShellOnline", "ActiveDirectory"
foreach ($Module in $Modules) {
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
if ( Get-Module -Name $Module ) {
Import-Module -Name $Module
Write-Warning "Module Import - Imported $Module"
}
else {
Write-Warning "Installing $Module"
$execpol = Get-ExecutionPolicy -List
if ( $execpol -ne 'Unrestricted' ) {
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
}
Install-Module -Name $Module -Scope AllUsers -AllowClobber
}
Set-PSRepository -Name PSGallery -InstallationPolicy Untrusted
}
# & (Join-Path ($PROFILE).TrimEnd('Microsoft.PowerShell_profile.ps1') "\Connect-Office365Services.ps1")
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.