Last active
May 29, 2023 03:28
-
-
Save cinnamondev/0997cbf17a54b086cecc507280fdd2da to your computer and use it in GitHub Desktop.
Fancy-Fetch is a powershell script for some fancy fetching of modules. (install local & fetch local). Usage: Fancy-Fetch foo,bar,baz -InstallDir "./blah" -Provider "PSGallery"
This file contains 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
function Fancy-Fetch { | |
param ( | |
[string[]]$Modules, | |
[string]$InstallDir = './.ps-modules/', | |
[string]$Provider = 'PSGallery' | |
) | |
if (!(Test-Path $InstallDir)) {New-Item $InstallDir -ItemType Directory} | |
$Modules | Foreach-Object { | |
# Pull powershell-yaml if not installed | |
$mod_installed = (Get-Module -ListAvailable -Name $_) | |
$loc_installed = (Test-Path -Path "${InstallDir}/${_}") | |
if (!$mod_installed -and !$loc_installed) { | |
if ($PSModule = Find-Module -Name $_ -Repository $Provider) { | |
Save-Module $_ -Path $InstallDir | |
} else { | |
throw "${_} was not avilable through ${Provider}, nor in ${InstallDir} ." | |
} | |
} | |
if ($mod_installed) { | |
Import-Module $_ | |
} else { | |
Import-Module -FullyQualifiedName "${InstallDir}/${_}" | |
} | |
} | |
} | |
Export-ModuleMember -Function Fancy-Fetch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment