Skip to content

Commit

Permalink
Update Remove-Old-Modules script (#5)
Browse files Browse the repository at this point in the history
* Updated remove-old-modules with params

added a module-name param to specify a single module to remove
added an -includeAll param that will grab all modules like the default is in older versions.
no params will now give message to included a module
-help param gives quick help
added support for get-help

* update readme with info on new parameters for the remove-old-modules script
  • Loading branch information
JasonLautzenheiser authored Apr 15, 2022
1 parent f6a4f92 commit 34baf6e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Powershell: Launch Current File w/ Params",
"type": "PowerShell",
"request": "launch",
"script": "${file}",
"args": ["fasf"],
"cwd": "${workspaceFolder}"
},
{
"name": "PowerShell: Launch Current File",
"type": "PowerShell",
"request": "launch",
"script": "${file}",
"cwd": "${file}"
}
]
}
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,22 @@ link to a zillion themes that you can simply copy and paste into your oh-my-conf
https://ohmyposh.dev/docs/themes#default


## Included Scripts

### Remove-Old-Modules
When you update modules, like oh-my-posh, multiple versions can stick around. If you want to clean them up, this script will help you out by removing old versions but leaving the most recent one installed.

```console
remove-old-modules <module-name>
```
pass in a module name to clean up old installs of the module passed in.

```console
remove-old-modules oh-my-posh
```
this will clean up older installed versions of oh-my-posh

```console
remove-old-modules -includeAll
```
This flag will remove all installed modules returned by a call to ```Get-InstalledModule ```
40 changes: 38 additions & 2 deletions scripts/Remove-Old-Modules.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
write-host "Remove old versions of installed modules."
<# .SYNOPSIS #>
param(
[Parameter()]
[string]$name,
[Parameter()]
[switch]$includeAll,
[Parameter()]
[switch]$help
)

$mods = Get-InstalledModule
if ($help) {
Write-Output "Usage: Remove-Old-Modules [-Name <string>] [-IncludeAll <switch>] [-Help <switch>]";
exit;
}

if ($includeAll.IsPresent) {
$mods = Get-InstalledModule
if ($mods.Count -eq 0)
{
write-host "No modules found."
exit 1
}

write-host "Removing old versions of installed modules."

} else {
if (!$name)
{
write-host "Please specify a module name."
exit 1
}

$mods = Get-InstalledModule $name
if ($mods.Count -eq 0)
{
write-host "Module $name not found."
exit 1
}
}

foreach ($module in $mods) {
Write-Host -Message "Removing old versions of $($module.Name) [latest is $( $module.Version)]"
Expand Down

0 comments on commit 34baf6e

Please sign in to comment.