Last active
December 1, 2025 21:54
-
-
Save jdhitsolutions/86f19d8b1079427cd70df0fe82396a2d to your computer and use it in GitHub Desktop.
Import a local module from a list. Requires PowerShell 7 and the pwshSpectreConsole module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #requires -version 7.5 | |
| #requires -module pwshSpectreConsole | |
| Function Import-LocalModule { | |
| [cmdletbinding()] | |
| [alias('ilm')] | |
| Param( | |
| [Parameter(Position = 0, HelpMessage = "The path to the module data JSON file")] | |
| [ValidateScript({Test-Path $_})] | |
| [string]$DataPath = "c:\scripts\LocalModuleData.json", | |
| [switch]$Passthru | |
| ) | |
| Write-Verbose "Getting local module data from $DataPath" | |
| $data = (Get-Content $DataPath | ConvertFrom-json).ModuleInfo | |
| #use inline formatting supported by pwshSpectreConsole | |
| $splat = @{ | |
| Message = "`n[italic Chartreuse1]Select one or more local modules to import[/]" | |
| AllowEmpty = $true | |
| Color = "Chartreuse1" | |
| Choices = $Data | |
| ChoiceLabelProperty = "ModuleTitle" | |
| PageSize = 7 | |
| } | |
| $r = Read-SpectreMultiSelection @splat | |
| if ($r) { | |
| $r.Foreach({ | |
| Write-SpectreHost "Importing [green italic]$($_.ModuleName)[/] from [green italic]$($_.Path)[/]" | |
| Write-Verbose "Importing module from $($_.path)" | |
| Import-Module -Name $_.path -Force -Scope Global | |
| If ($Passthru) { | |
| Get-Module -Name $_.ModuleName | |
| } | |
| }) | |
| } | |
| else { | |
| Write-SpectreHost "[OrangeRed1]No modules selected[/]" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MIT License | |
| Copyright (c) 2025 JDH Information Technology Solutions, Inc. | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in | |
| all copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
| THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$schema": "file:///c:/scripts/localmodules2.schema.json", | |
| "moduleInfo": [ | |
| { | |
| "moduleTitle": "PS Tools", | |
| "moduleName": "PSTools", | |
| "path": "c:\\scripts\\PSTools\\PSTools.psd1" | |
| }, | |
| { | |
| "moduleTitle": "MuseScore Tools", | |
| "moduleName": "MuseScoreTools", | |
| "path": "c:\\scripts\\MuseScoreTools\\MuseScoreTools.psd1" | |
| } | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$schema": "https://json-schema.org/draft/2020-12/schema", | |
| "title": "PowerShell Local Modules Configuration", | |
| "description": "Schema for listing PowerShell modules with their titles, names, and file paths", | |
| "type": "object", | |
| "moduleInfo": { | |
| "type": "array", | |
| "description": "Local module details", | |
| "items": { | |
| "type": "object", | |
| "properties": { | |
| "moduleTitle": { | |
| "type": "string", | |
| "description": "Display name or title of the PowerShell module" | |
| }, | |
| "moduleName": { | |
| "type": "string", | |
| "description": "Technical name of the PowerShell module" | |
| }, | |
| "path": { | |
| "type": "string", | |
| "description": "File system path to the module manifest (.psd1) or script module (.psm1) file", | |
| "pattern": "^[a-zA-Z]:\\\\.*\\.(psd1|psm1)$" | |
| } | |
| }, | |
| "required": [ | |
| "moduleTitle", | |
| "moduleName", | |
| "path" | |
| ] | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment