What’s the Best Way to Remove Specific Module Versions in PowerShell?

0
0
Asked By CuriousCoder92 On

I'm trying to figure out how to efficiently remove specific module versions in PowerShell, particularly for the Microsoft.Graph module which comes in multiple versions. I've looked into different management tools for modules, but they seem too complicated for what I need.

Currently, all my modules are installed using `Install-Module`, and I've experimented with `Uninstall-PSResource` using wildcards, but sometimes I run into issues like permission errors or missing modules even when targeting the CurrentUser scope.

To tackle this, I've resorted to a manual script that feels clunky:

```powershell
$RemoveVersion = [System.Version]'2.27.0'
Get-Module -ListAvailable | where {$_.Name -like 'Microsoft.Graph*' -and $_.Version -eq $RemoveVersion} | foreach {$_;Uninstall-Module $_.Name -RequiredVersion $RemoveVersion -Force}
```

I'm not in a rush and just want to clean up specific versions rather than uninstalling everything. Any tips or better methods would be appreciated!

3 Answers

Answered By ModuleMaster89 On

I usually take a manual approach for cleanup. I use version pinning to ensure I'm not impacted by unexpected changes when team members update modules. For example, utilizing `#Requires` or `Import-Module` with a specified version helps me avoid breaking changes that could disrupt production. It's a lot less hassle than uninstalling. Just keep an eye on the versions you're using!

TeamPlayer7 -

I like the idea of #Requires too! For now, I’m just notifying users with warnings in the modules about potential issues with current SDK bugs, but forcing a specific version might be the safer route.

Answered By CICDGuru On

My team's modules are managed through our CI/CD pipeline. We deploy only specific versions, and I periodically commit updates for all modules—pretty much the pipeline does the heavy lifting for me! I’ve avoided updating Graph modules often because of the DLL incompatibilities with AZ modules.

Answered By VersionVanquisher On

Handling multiple versions of MS Graph can be a pain. I typically run a script like this:

```powershell
Uninstall-Module Microsoft.Graph -RequiredVersion 2.27.0
Get-InstalledModule Microsoft.Graph.* | %{ if(($_.Name -ne "Microsoft.Graph.Authentication") -and ($_.Version -eq "2.27.0")){ Uninstall-Module $_.Name } }
Uninstall-Module Microsoft.Graph.Authentication -RequiredVersion 2.27.0
```
It’s straightforward and does the job nicely!

InspectorGadget88 -

Exactly! I had someone with Graph 2.28.0 installed and it messed with their scripts. It’s such a hassle—cleaning up modules is a must.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.