Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JPRuskin
Last active May 29, 2019 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPRuskin/5fb0879e92267910d67cf91d89c34ad7 to your computer and use it in GitHub Desktop.
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.
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 ';'
}
}
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