Automate PowerShell Module Updates: Never Manually Update Again
Stop the Manual PowerShell Module Update Madness
How many times have you opened PowerShell, run a command, and been greeted with that familiar yellow warning about outdated modules? If you’re like most IT professionals, you’ve probably ignored it more often than you’d care to admit. Today, we’re fixing that with a comprehensive automation solution.
The Problem We’re Solving
Managing PowerShell modules manually is a pain. Here’s what typically happens:
- ⚠️ Outdated modules cause compatibility issues
- 🐌 Manual updates are time-consuming and error-prone
- 🗄️ Multiple versions clutter your system
- 😤 Inconsistent environments across your team
Sound familiar? Let’s automate this away.
The Solution: Smart Module Management
I’ve created a comprehensive PowerShell script that handles all of this automatically. Version 2.0 brings major enhancements including parallel processing for PowerShell 7+ and intelligent error handling. It’s not just another update script – it’s a complete module lifecycle manager that:
- ✅ Updates all modules to the latest versions with parallel processing (PowerShell 7+)
- 🧹 Cleans up old versions automatically to prevent conflicts
- 🚀 Supports both stable and pre-release versions
- 🛡️ Includes comprehensive error handling and detailed logging
- � Provides detailed progress reporting and status updates
- 🎯 Flexible scope management (CurrentUser, AllUsers, or Both)
- ⚡ Intelligent processing - parallel for PowerShell 7+, optimized sequential for 5.1
Download the Complete Script
You can download the latest version of the script from my GitHub repository:
Quick Start Examples
Basic Usage (Recommended)
1
.\Update_Modules.ps1
Updates all modules to latest stable versions using intelligent processing
Update Specific Modules
1
.\Update_Modules.ps1 -Name "Az*", "Microsoft.Graph*"
Updates only Azure and Microsoft Graph modules
Power User Mode with Prerelease
1
.\Update_Modules.ps1 -AllowPrerelease -Force -Verbose
Gets bleeding-edge versions with detailed output and forced updates
Test Run (What-If Mode)
1
.\Update_Modules.ps1 -WhatIf
Shows what would be updated without making changes
Scope-Specific Updates
1
.\Update_Modules.ps1 -Scope CurrentUser
Updates only user-scope modules
How It Works
The script follows a sophisticated, optimized approach:
- Environment Detection - Identifies PowerShell version for optimal processing method
- Module Discovery - Catalogs installed modules with flexible filtering options
- Intelligent Processing - Uses parallel processing (PowerShell 7+) or optimized sequential processing (5.1)
- Smart Updates - Handles known problematic modules with special logic
- Version Management - Automatically cleans up old versions to prevent conflicts
- Comprehensive Logging - Detailed logging with timestamp and error tracking
- Results Summary - Clear reporting of what was updated, current, or failed
Key Features in Version 2.0
Parallel Processing (PowerShell 7+)
For PowerShell 7 and later, the script uses ForEach-Object -Parallel
to process multiple modules simultaneously, dramatically reducing update time for environments with many modules.
Enhanced Error Handling
- Special handling for known problematic modules (Az.ConfidentialLedger, Az.StorageSync, Microsoft.Graph.Compliance)
- Detailed error logging with timestamps
- Graceful fallback methods for difficult modules
Flexible Scope Management
- CurrentUser: Updates only user-installed modules
- AllUsers: Updates only system-wide modules
- Both: Updates all modules regardless of scope (default)
Progress Reporting
- Real-time progress indicators
- Color-coded status messages
- Detailed summary reports
The Complete Script Parameters
The enhanced script offers comprehensive configuration options:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<#
.SYNOPSIS
Updates PowerShell modules to their latest versions with enhanced error handling and parallel processing.
.PARAMETER Name
Specifies module names to update. Supports wildcards. Default is '*' for all modules.
.PARAMETER AllowPrerelease
If specified, allows updating to prerelease versions.
.PARAMETER WhatIf
Shows what would happen without making changes.
.PARAMETER Force
Forces updates even if modules appear up-to-date.
.PARAMETER ThrottleLimit
Maximum concurrent operations for PowerShell 7+ (1-10). Default is 3.
.PARAMETER Scope
Specifies the scope for module operations. Options: CurrentUser, AllUsers, Both. Default is 'Both'.
.PARAMETER SkipOldVersionCleanup
If specified, does not remove old module versions after update.
.EXAMPLE
.\Update_Modules.ps1
Updates all installed modules to their latest stable versions.
.EXAMPLE
.\Update_Modules.ps1 -Name "Az*" -AllowPrerelease -Verbose
Updates all Az modules to latest versions including prereleases with verbose output.
.EXAMPLE
.\Update_Modules.ps1 -WhatIf
Shows what modules would be updated without making changes.
.NOTES
Author: Matthew Miles
Version: 2.0
Compatible: PowerShell 5.1+ (optimized for 7+)
#>
Sample Output
Here’s what you’ll see when running the script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[2025-09-06 14:30:15] [Info] Starting module update process...
[2025-09-06 14:30:15] [Info] PowerShell Version: 7.4.0
[2025-09-06 14:30:16] [Info] Found 45 modules to process
[2025-09-06 14:30:16] [Info] Using parallel processing (ThrottleLimit: 3)
[2025-09-06 14:30:16] [Info] Processing modules... (this may take a few minutes)
+ Updated: Az.Accounts (2.12.1 -> 2.12.5)
+ Updated: Microsoft.Graph.Authentication (1.28.0 -> 2.8.0)
= Current: PowerShellGet (3.0.17)
- Failed: Az.ConfidentialLedger - Known compatibility issue
=== UPDATE SUMMARY ===
Successfully updated modules:
* Az.Accounts: 2.12.1 -> 2.12.5
* Microsoft.Graph.Authentication: 1.28.0 -> 2.8.0
Failed to update modules:
* Az.ConfidentialLedger: Known compatibility issue
Processed: 45 | Updated: 2 | Current: 42 | Failed: 1
Run This Monthly
Add this to your monthly maintenance routine. Here are several automation options:
Scheduled Task (Windows)
1
2
3
4
5
# Create a scheduled task to run monthly
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\Update_Modules.ps1"
$Trigger = New-ScheduledTaskTrigger -Monthly -At "2:00 AM"
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
Register-ScheduledTask -TaskName "PowerShell Module Updates" -Action $Action -Trigger $Trigger -Settings $Settings
PowerShell Profile Integration
Add to your PowerShell profile for manual runs:
1
2
3
4
# Add to $PROFILE
function Update-MyModules {
& "C:\Scripts\Update_Modules.ps1" @args
}
Test Before Production
Always test module updates in a development environment first, especially when using -AllowPrerelease
:
1
2
3
4
5
# Test what would be updated
.\Update_Modules.ps1 -WhatIf -Verbose
# Update only specific modules first
.\Update_Modules.ps1 -Name "Az.Accounts", "Microsoft.Graph.Authentication"
Advanced Usage Tips
Performance Optimization
- Use
-ThrottleLimit
to control parallel processing (PowerShell 7+) - Consider
-Scope CurrentUser
for faster personal environment updates - Use
-Name
parameter to target specific modules rather than updating everything
Troubleshooting Failed Updates
The script handles known problematic modules automatically, but if you encounter issues:
- Check the detailed log file (location shown in output)
- Try updating individual modules manually
- Use
-Force
parameter for stubborn modules - Consider
-SkipOldVersionCleanup
if cleanup is causing issues
Document Your Dependencies
Keep track of which modules your scripts depend on. Consider using a requirements.psd1
file for your projects.