Last active
May 29, 2019 10:24
-
-
Save JPRuskin/5fb0879e92267910d67cf91d89c34ad7 to your computer and use it in GitHub Desktop.
Function/Script to add a saved module from C:\Modules, as the AzureDevOps build machines seem to. Worked into the SimpleAzureModule 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
function Add-AzureModule { | |
[CmdletBinding(DefaultParameterSetName="Calculated")] | |
param( | |
[Parameter(ParameterSetName="Calculated", Position=0)] | |
[ArgumentCompleter({ | |
param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $BoundParams) | |
(Get-ChildItem C:\Modules\).Where({$_ -like "*$WordToComplete*_*"}).Name | %{$_.Split('_')[0]} | Sort-Object -Unique | |
})] | |
[string]$Name, | |
[Parameter(ParameterSetName="Calculated", Position=1)] | |
[ArgumentCompleter({ | |
param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $BoundParams) | |
$BoundName = $BoundParams.Name | |
(Get-ChildItem C:\Modules\).Where({$_ -like "$BoundName`_*"}).Name | %{$_.Split('_')[1]} | |
})] | |
[version]$Version, | |
[Parameter(ParameterSetName="Provided", Position=0)] | |
[ValidateScript({Test-Path $_ -PathType Container})] | |
[string]$Path = "C:\Modules\$Name`_$Version" | |
) | |
end { | |
$ModulePath = $env:PSModulePath.Split(';') | |
$env:PSModulePath = @() + $Path + $ModulePath.Where({$_ -notlike "C:\Modules\*"}) -join ';' | |
} | |
} |
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
function Save-AzureModule { | |
[CmdletBinding()] | |
param( | |
[ValidateSet("AzureRm","Az")] | |
[string]$Name, | |
[version]$RequiredVersion | |
) | |
process { | |
$BasePath = "C:\Modules" | |
$ModulePath = Join-Path $BasePath "$Name`_$Version" | |
if (-not (Test-Path -Path $ModulePath -PathType Container)) { | |
$null = New-Item -Path $ModulePath -ItemType Directory | |
} | |
Save-Module @PSBoundParameters -Path $ModulePath | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment