Install PowerShell 7 and modules

Compare the recorded PowerShell 5.1/7 deployment choices and module-installation examples for Microsoft 365 administration. Version and installation observations belong to the captured environment.

Use Powershell 5.1 or 7?

When choosing your version you need to ask 1 question: Q: Does the .ps1 script need to run on a Windows endpoint (laptop/desktop)? IF Yes, your code must work in powershell 5.1

  • Powershell 5.1(As at 20Jan2026) is still the default version of powershell that is shipped with Windows 11.
  • For ease of deployment, where you can, you will want to stick with powershell 5.1 modules that are built-in to Windows.
  • Module Not Installed?: If you have a script written for powershell 5.1 with functions from a powershell module that is not included with PS 5.1 on Windows, then you should install/deploy the module to the target endpoints before you deploy your script.

IF No, you should use powershell 7

  • Powershell 7 can run on linux, MacOSX and Windows but it will require you to download and install it.
  • Where possible use Powershell 7 because it is where MS is putting all of it's development energies.
  • AutoComplete: has an auto complete that will reveal the available parameters for a function/command.

EXE Powershell 5.1 powershell.exe

EXE Powershell 7 pwsh.exe

WARNING: DO NOT INSTALL POWERSHELL 7 FROM THE WINDOWS APP STORE

If pwsh.exe has been installed via the MS Windows App Store, the pwsh.exe will not run in a scheduled task.

QUICK START: SUMMARY OF THE SECTIONS BELOW

You should be able to execute the code in this section and start using powershell 7 with M365.

Step1: Install Powershell 7 (Make sure you are using powershell 7.4 or higher.

winget install -e --id=Microsoft.PowerShell

Step2: Open powershell 7 Terminal as Administrator (The how-to for these steps are below)

Step3: Set Execution Policy for current User

Set-Executionpolicy -Scope CurrentUser -executionpolicy remotesigned -Force

PowerShellGet (using Install-Module) is being replaced by PSResourceGet (using Install-PSResource) Note: Powershell 7.4 and higher it comes with Microsoft.PowerShell.PSResourceGet

WHY PSResourceGet?

PSResourceGet is much faster than PowerShellGet

Step4: Set PSGallery as a trusted respository

Set-PSResourceRepository -Name "PSGallery" -Trusted

Step5: Install Modules #For "Microsoft.Graph*"

Find-PSResource -Name "Microsoft.Graph*" -Type Module | Install-PSResource -Scope CurrentUser

#For "Microsoft.Graph.Beta*"

Find-PSResource -Name "Microsoft.Graph.Beta*" -Type Module | Install-PSResource -Scope CurrentUser

#For "Microsoft.Entra*"

Find-PSResource -Name "Microsoft.Entra*" -Type Module | Install-PSResource -Scope CurrentUser

#For "Microsoft.Entra.Beta*"

Find-PSResource -Name "Microsoft.Entra.Beta*" -Type Module | Install-PSResource -Scope CurrentUser

#For "Microsoft.Entra.Beta*"

Find-PSResource -Name "Install-Module Az*" -Type Module | Install-PSResource -Scope CurrentUser

# For "ExchangeOnlineManagement" (no wildcard needed)

Install-PSResource -Name "ExchangeOnlineManagement" -Scope CurrentUser -NoClobber

Further module-installation examples follow below.

INSTALLING POWERSHELL AND MODULES

Powershell 7 Auto Complete: Example of Auto complete from pwsh command line (Terminal):

type in Get-Date - then hold Ctrl and press space Ctrl+Space and you will see all the available parameters

Screenshot retained for review

Modules: Installation Folder Locations for Powershell 5.1 and 7 Scope "CurrentUser"

  • Powershell 7: …Documents\powershell\Modules
  • Powershell 5.1: …Documents\WindowsPowerShell\Modules

Scope "AllUsers"

  • Powershell 7:

C:\Program Files\PowerShell\Modules

  • Powershell 5.1 C:\Program Files\WindowsPowerShell\Modules

STEP1: Install Powershell 7/pwsh.exe:

Use WinGet (Recommended By MS) Install PowerShell on Windows - PowerShell | Microsoft Learn

winget install -e --id=Microsoft.PowerShell

STEP2: Open Powershell 7 as Administrator (See Screenshot)

  • Open Terminal App
  • Click the session type selector
  • Hold the Ctrl key and Click Powershell (Ctrl+Click Powershell)

Screenshot retained for review

STEP3: Install Modules for Powershell 7

The source reports needing "AllowClobber" for MS Graph and Entra with Install-Module, but not for its other modules. Note that when using Install-PSResource, allowClobber is enabled by default. If you want to disable AllowClobber you need to use -NoClobber (See Install-PSResource -Name "ExchangeOnlineManagement" below for an example) Note: The install of the Az module gets it's own step below because it can be painful.

If need for powershell 5.1 Install-Module -Name "PowershellGet" -AllowClobber -Scope CurrentUser -Confirm:$false Install-Module -Name "Microsoft.Graph*" -AllowClobber -Scope CurrentUser -Confirm:$false

Install-Module -Name "Microsoft.Graph.Beta*" -AllowClobber -Scope CurrentUser -Confirm:$false
Install-Module -Name "Microsoft.Entra*" -AllowClobber -Scope CurrentUser -Confirm:$false
Install-Module -Name "Microsoft.Entra.Beta*" -AllowClobber -Scope CurrentUser -Confirm:$false
Install-Module -Name "ExchangeOnlineManagement" -Scope CurrentUser -Confirm:$false

For powershell 7.4+

First you need to trust the PSGallery: Set-PSResourceRepository -Name "PSGallery" -Trusted

Note: Install-PSResource does not take wild cards so pipe the names in with Find-PSResource

#NOTE: If you don't use the loop below you can end up install multiple versions of the same sub module.

#THIS WILL END UP INSTALLING MULTIPLE VERSIONS OF EACH SUBMODULE.

#The * in the Name is a wild card to select all submodules, Microsoft.Graph.Authentication, Microsoft.Graph.User etc… #When Find-PSResource is piped into Install-PSResource and the Name parameter ends with *, then multiple versions of each submodule will be downloaded/installed.

#Example(Don't use): Find-PSResource -Name "Microsoft.Graph*" -Type Module | Install-PSResource -Scope CurrentUser

#To download just the latest version of each submodule, the source uses the following. #When Find-PSResource is piped into Install-PSResource without the * in the Name parameter, then only the latest version of each submodule will be downloaded/installed.

INSTALL MODULES THAT HAVE AND INCLUDE THEIR SUBMODULES

#PowerShell modules with submodules selected in this example. #Only install "Az.*" if you need it, it takes up 2GB.

$listOfMultiModulesWithSubmodules = @("Microsoft.Graph*","Microsoft.Graph.Beta*","Microsoft.Entra*","Microsoft.Entra.Beta*","Az.*")
$myModuleList = $listOfMultiModules | ForEach-Object {
$Module_Name = $_

(Find-PSResource -Name "($Module_Name)" -Type Module) | Sort-Object Name | Select-Object Name -Unique -ExpandProperty Name

}

#INSTALL ALL MODULES and SUBMODULES THAT WERE FOUND BY Find-PSResource

$($myModuleList).Name | Install-PSResource -Scope CurrentUser

INSTALL MODULES THAT HAVE NO SUBMODULES

$listOfSingleModules = @("PnP.PowerShell","ExchangeOnlineManagement","WindowsAutoPilotIntune","MicrosoftTeams","ImportExcel","Join-Object","MsrcSecurityUpdates","Pester","Microsoft365DSC","PSParseHTML")
$modulesWithNoSubmodules = $listOfSingleModules | foreach {

$Module_Name = $_ Install-PSResource -Name "$($Module_Name)" -Scope CurrentUser }

# For "ExchangeOnlineManagement" (no submodules to no wildcard needed)

Install-PSResource -Name "ExchangeOnlineManagement" -Scope CurrentUser -NoClobber

OTHER HELPFUL MODULES

Template for installing the modules: Windows Powershell 5.1

Install-Module -Name "Insert a Module name from the list below" -Scope CurrentUser -Confirm:$false
Windows Powershell 7
Install-PSResource -Name "Insert a Module name from the list below" -Scope CurrentUser -NoClobber

ImportExcel (A truly wonderful module that makes xlsx files from csv and it allows you to free top row and make bold, add filter.

MicrosoftTeams

PnP.PowerShell (For working with Sharepoint) Microsoft.Entra

WindowsAutoPilotIntune

Microsoft365DSC (Desired State Configuration (DSC). Allows you to save and compare M365 cloud configurations. Can compare current config with ACSC DSC etc…)

Join-Object (See Join-Object/README.md at master · ili101/Join-Object · GitHub)

PSParseHTML

MsrcSecurityUpdates

Pester (Haven't used yet, but want to. It's a testing framework)

platyPS (Allows you to create PowerShell External Help in Markdown)

Array of the above list if you wanted to use it.

STEP4: Install the Az Module

(Install Azure PowerShell with PowerShellGet | Microsoft Learn**)**

Az module is used for managing Azure Resources. For example, to get DNS records from Azure you need this module.

The Pain: This one can be a pain to install as it wasn't downloading the newest Az.Account. Then upgrading can also be painful (

If first time installing install with

3A) Open Powershell as Administrator 3B) Install-Module -Name Az -Repository PSGallery -MinimumVersion 15.2.0 -Force -Scope "CurrentUser"

OR

Find-PSResource -Name "Az.*" -Type Module | Install-PSResource -Scope CurrentUser

Check for all installed Versions of Az

Get-InstalledModule -Name Az -AllVersions | Select-Object -Property Name, Version

HOW TO Uninstall Powershell Modules

Uninstall approach recorded in the source

The author describes manually deleting module folders, explicitly noting that this is not the Microsoft-recommended method. This companion does not validate or recommend that deletion approach. The captured example targets folders matching Microsoft.Graph* beneath the user Documents/PowerShell/Modules directory.

Example 2: Uninstalling Az Goto: …Documents\powershell\Modules Delete all the folders that match "Az.*"

You may also need to check and delete folders from these (scope "AllUsers") folders: C:\Program Files\PowerShell\Modules

C:\Program Files\WindowsPowerShell\Modules

4. (Optional) Scan your C drive for other powershell module locations.

Searching for the powershell modules on your computer using an app called Everything by voidtools.

Install using winget: winget install -e --id=voidtools.Everything