# Update-Module.ps1

# Table of Contents

  • Purpose
  • Dependencies
  • Function
  • Usage
  • Inputs
  • Variables
  • Command Line Flags
  • Outputs
  • Notes

# Purpose

Updates all installed PowerShell modules from the PowerShell Gallery to their latest available versions, with options to exclude modules, skip major version updates, and remove old versions. Designed for robust, unattended module maintenance.

# Dependencies

# Function

  1. Finds all installed modules from the PowerShell Gallery, excluding any specified in -ExcludedModules.
  2. For each module, checks if a newer version is available in PSGallery.
  3. If a newer version exists:
    • Optionally skips major version updates if -SkipMajorVersion is set.
    • Updates the module to the latest version.
    • Removes old versions unless -KeepOldModuleVersions is set or the module is in -ExcludedModulesforRemoval (default: Az).
  4. Handles errors and logs progress for each module.
  5. Provides verbose output and supports -WhatIf/-Confirm via SupportsShouldProcess.

# Usage

Run directly to update all modules:

./Update-Module.ps1 -Verbose

Or, from within another script (dot-source if you want to call the function directly):

. "C:\Path\To\Update-Module.ps1"
Update-EveryModule -ExcludedModules 'Module1','Module2' -SkipMajorVersion -Verbose

# Inputs

  • -ExcludedModules (array, optional): Modules to exclude from updating.
  • -SkipMajorVersion (switch, optional): Skip major version updates to avoid breaking changes.
  • -KeepOldModuleVersions (switch, optional): Keep old versions of modules after updating.
  • -ExcludedModulesforRemoval (array, optional): Modules to exclude from removal of old versions (default: Az).

# Variables

  • $CurrentModules: List of installed modules to check for updates.
  • $GalleryModule: Latest version info from PSGallery for each module.
  • $ExcludedModules, $SkipMajorVersion, $KeepOldModuleVersions, $ExcludedModulesforRemoval: Parameters controlling update/removal logic.

# Command Line Flags

  • -Verbose: Shows detailed progress and actions.
  • -WhatIf/-Confirm: Supported for safe execution/testing.
  • All function parameters above can be used as flags if calling Update-EveryModule directly.

# Outputs

  • Updates modules to the latest version from PSGallery.
  • Removes old versions unless excluded or instructed to keep.
  • Logs progress, warnings, and errors to the console.

# Notes

  • The script runs Update-EveryModule -Verbose by default when executed.
  • Designed for PowerShell 7+ and robust unattended use.
  • Excludes the Az module from removal by default for stability.
  • All output is accessible and uses EN-AU spelling.
  • See project standards for robust root-based module import and error handling.