2019-12-13 09:48:00 -05:00
|
|
|
################################################################################
|
|
|
|
|
## File: Install-AzureModules.ps1
|
|
|
|
|
## Desc: Install Azure PowerShell modules
|
|
|
|
|
################################################################################
|
|
|
|
|
|
2020-07-01 15:16:01 +03:00
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
|
|
|
# The correct Modules need to be saved in C:\Modules
|
|
|
|
|
$installPSModulePath = $env:PSMODULES_ROOT_FOLDER
|
|
|
|
|
if (-not (Test-Path -LiteralPath $installPSModulePath))
|
2019-12-13 09:48:00 -05:00
|
|
|
{
|
2020-07-01 15:16:01 +03:00
|
|
|
Write-Host "Creating ${installPSModulePath} folder to store PowerShell Azure modules..."
|
2020-02-25 19:20:15 +03:00
|
|
|
$null = New-Item -Path $installPSModulePath -ItemType Directory
|
2019-12-13 09:48:00 -05:00
|
|
|
}
|
|
|
|
|
|
2020-07-01 15:16:01 +03:00
|
|
|
# Get modules content from toolset
|
|
|
|
|
$modules = (Get-ToolsetContent).azureModules
|
2019-12-13 09:48:00 -05:00
|
|
|
|
2020-07-01 15:16:01 +03:00
|
|
|
$psModuleMachinePath = ""
|
2019-12-13 09:48:00 -05:00
|
|
|
|
2020-07-01 15:16:01 +03:00
|
|
|
foreach ($module in $modules)
|
2019-12-13 09:48:00 -05:00
|
|
|
{
|
2020-07-01 15:16:01 +03:00
|
|
|
$moduleName = $module.name
|
|
|
|
|
|
|
|
|
|
Write-Host "Installing ${moduleName} to the ${installPSModulePath} path..."
|
|
|
|
|
foreach ($version in $module.versions)
|
2019-12-13 09:48:00 -05:00
|
|
|
{
|
2020-07-01 15:16:01 +03:00
|
|
|
$modulePath = Join-Path -Path $installPSModulePath -ChildPath "${moduleName}_${version}"
|
|
|
|
|
Write-Host " - $version [$modulePath]"
|
2019-12-13 09:48:00 -05:00
|
|
|
try
|
|
|
|
|
{
|
2020-07-01 15:16:01 +03:00
|
|
|
Save-Module -Path $modulePath -Name $moduleName -RequiredVersion $version -Force -ErrorAction Stop
|
2019-12-13 09:48:00 -05:00
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2020-02-25 19:20:15 +03:00
|
|
|
Write-Host "Error: $_"
|
|
|
|
|
exit 1
|
2019-12-13 09:48:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
2020-07-01 15:16:01 +03:00
|
|
|
|
|
|
|
|
# Append default tool version to machine path
|
|
|
|
|
if ($null -ne $module.default)
|
|
|
|
|
{
|
|
|
|
|
$defaultVersion = $module.default
|
|
|
|
|
|
|
|
|
|
Write-Host "Use ${moduleName} ${defaultVersion} as default version..."
|
|
|
|
|
$psModuleMachinePath += "${installPSModulePath}\${moduleName}_${defaultVersion};"
|
|
|
|
|
}
|
2019-12-13 09:48:00 -05:00
|
|
|
}
|
|
|
|
|
|
2020-07-01 15:16:01 +03:00
|
|
|
# Add modules to the PSModulePath
|
|
|
|
|
$psModuleMachinePath += $env:PSModulePath
|
2020-07-21 09:50:01 +03:00
|
|
|
[Environment]::SetEnvironmentVariable("PSModulePath", $psModuleMachinePath, "Machine")
|
|
|
|
|
|
|
|
|
|
Invoke-PesterTests -TestFile "PowerShellModules" -TestName "AzureModules"
|