Created
October 4, 2018 09:22
-
-
Save kilasuit/190c5085ff8a119632e76ef18b87ae1a to your computer and use it in GitHub Desktop.
Install-ModuleFix.ps1
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 Install-ModuleFix { | |
<# | |
.SYNOPSIS | |
Describe purpose of "Install-ModuleFix" in 1-2 sentences. | |
.DESCRIPTION | |
Add a more complete description of what the function does. | |
.PARAMETER Module | |
Describe parameter -Module. | |
.PARAMETER ReqVersion | |
Describe parameter -ReqVersion. | |
.EXAMPLE | |
Install-ModuleFix -Module Value -ReqVersion Value | |
Describe what this call does | |
.NOTES | |
Place additional notes here. | |
.LINK | |
URLs to related sites | |
The first link is opened by Get-Help -Online Install-ModuleFix | |
.INPUTS | |
List of input types that are accepted by this function. | |
.OUTPUTS | |
List of output types produced by this function. | |
#> | |
[cmdletbinding()] | |
Param( | |
[Parameter(Mandatory, | |
HelpMessage='Add help message for user', | |
ValueFromPipelineByPropertyName)] | |
[String]$Module, | |
[Parameter(Mandatory, | |
HelpMessage='Add help message for user', | |
ValueFromPipelineByPropertyName)] | |
[String]$ReqVersion | |
) | |
$modules = Find-module -Name $module -RequiredVersion $ReqVersion -IncludeDependencies -Verbose:$VerbosePreference | |
$mods = New-Object -TypeName System.Collections.ArrayList -Verbose:$VerbosePreference | |
If ($Module -eq 'AzureRM'){ | |
$mods.add(($modules | Where-Object -Property Name -EQ -Value AzureRM.Profile | Where-Object Version -ne 2.1.0)) | |
$modules | Where-Object -Property Name -NE -Value AzureRM.Profile | ForEach-Object { $mods.Add($_) } | |
} | |
else | |
{ | |
$modules | ForEach-Object { $mods.Add($_) } | |
} | |
$mods.ForEach{$ModuleName = $_.Name | |
$ModuleVersion = $_.Version | |
$file = 'https://www.powershellgallery.com/api/v2/package/{0}/{1}' -f $ModuleName,$ModuleVersion | |
$ModulePath = ('\{0}\{1}\' -f $ModuleName, $ModuleVersion) | |
$tempfilepath = ('{0}\PSGalleryFix{1}{2}.{3}.zip' -f $env:TEMP, $ModulePath, $ModuleName, $ModuleVersion) | |
$null = New-Item -Path $env:TEMP\PSGalleryFix\$ModulePath -ItemType Directory -Force -Verbose:$VerbosePreference | |
Invoke-WebRequest -Uri $file -UseBasicParsing -OutFile $tempfilepath -Verbose:$VerbosePreference | |
$ExpandPath = ('{0}\WindowsPowerShell\Modules{1}' -f $env:ProgramFiles, $ModulePath) | |
Expand-Archive -Path $tempfilepath -DestinationPath $ExpandPath -Force -Verbose:$VerbosePreference | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment