Caution
Don't run random scripts from the internet.
- This script is provided as-is, you should run it with caution.
- If it breaks anything on your computer it's your fault.
A script that installs, updates (and cleans up old versions), and removes PowerShell modules and scripts.
The script is self contained and maintains its' own version of the Microsoft.PowerShell.PSResourceGet
module:
- Self contained in
%LOCALAPPDATA%\Microsoft\PowerShell\PowerShellModulesUpdater
, outside of where other modules are installed. - Installed manually by downloading latest stable version from PowerShellGallery.
- Ensures the ability to:
- Update any module, also
Microsoft.PowerShell.PSResourceGet
. - Always use latest stable
Microsoft.PowerShell.PSResourceGet
, whether the user wants it in its'$env:PSModulePath
or not.
- Update any module, also
- Since PSScriptAnalyzer loads modules and DLLs in the background for doing script analysis, the script have to check if an older
PSResourceGet
assembly / DLL is already loaded in the session. If it is the script must use whatever version ofPSResourceGet
is already loaded.
The script originally ran on Windows using Windows PowerShell only.
Since v1.17.0 the script can run on both (1) PowerShell and (2) Windows PowerShell.
- PowerShell >= 7.3.X: Directly, or in Visual Studio Code with the PowerShell extension.
- Windows PowerShell 5.1: Directly, in PowerShell ISE, or in Visual Studio Code with the PowerShell extension.
Since v1.18.0 the script runs on both Windows and Linux. Probably MacOS too, but I don't have hardware to test that.
Module install directory path is hard coded in both scopes (AllUsers, CurrentUser), both for:
- Installing modules
- Workarounds:
- PackageManagement:
Save-Package
- PowerShellGet v3:
Save-PSResource
- PowerShellGet v2:
Save-Module
- PackageManagement:
- Related issues:
- 2022-04-07: PowerShell/PSResourceGet#627
- Workarounds:
- Searching for installed modules
- Workarounds:
- Custom logic: Modules versions folders where the hidden file
PSGetModuleInfo.xml
is present. Microsoft.PowerShell.Core\Get-Module
.Microsoft.PowerShell.PSResourceGet\Get-InstalledPSResource
with-Path
.
- Custom logic: Modules versions folders where the hidden file
- Related issues:
- 2023-01-12: PowerShell/PSResourceGet#889
- Workarounds:
Does not support semantic versioning v2.0.0
- Dotnet issue 2016-11-09: dotnet/runtime#19317
- PowerShell issue 2017-01-10: PowerShell/PowerShell#2983
- Stuck on NuGet API v2
- Poorly documented.
- A lot of useful filtering and searching functionality does not work.
- Meta issue and feature request for PowerShell modules to be hosted on NuGet Gallery: NuGet/NuGetGallery#10071.
sortBy=Version desc
does not work.
- Some version numbers can't be parsed/read as
[System.Version]
and PowerShell does not have proper semantic versioning support, nor NuGet.Versioning.
- Can't handle version numbers that can't be parsed as
[System.Version]
.- Example:
PowerShellGet
beta version3.0.12-beta
.
- Example:
- No logic for handling scenarios like:
- Pre-release version and stable version installed of the same module.
- Don't validate such version numbers at all.
If raw version can't be parsed, manually parse it.
- Regex to remove info that can't be parsed as
[System.Version]
, store it somewhere. ####### Ideas - Create own class for handling version numbers that
[System.Version]
does not handle? - Add a attribute to the object "nonstable", if raw version can't be parsed as
[System.Version]
?
- Get version info for all installed versions, and newest available version, using PowerShellGallery API.
- Slow