Files
runner-images-sangeeth/images/win/scripts/Installers/Install-AzureModules.ps1
Maksim Petrov 8ce91e3c37 [Windows] Install AZ 4.3.0 (#1137)
* Install and validate AZ 4.3.0 for Windows images

* Move azureModules to toolset

* Fix validation

* Fix modules root location

* Small fix in syntax

* Fix in syntax

* Fixes for default tool versions
2020-07-01 15:16:01 +03:00

55 lines
1.8 KiB
PowerShell

################################################################################
## File: Install-AzureModules.ps1
## Desc: Install Azure PowerShell modules
################################################################################
$ErrorActionPreference = "Stop"
Set-PSRepository -InstallationPolicy Trusted -Name PSGallery
# The correct Modules need to be saved in C:\Modules
$installPSModulePath = $env:PSMODULES_ROOT_FOLDER
if (-not (Test-Path -LiteralPath $installPSModulePath))
{
Write-Host "Creating ${installPSModulePath} folder to store PowerShell Azure modules..."
$null = New-Item -Path $installPSModulePath -ItemType Directory
}
# Get modules content from toolset
$modules = (Get-ToolsetContent).azureModules
$psModuleMachinePath = ""
foreach ($module in $modules)
{
$moduleName = $module.name
Write-Host "Installing ${moduleName} to the ${installPSModulePath} path..."
foreach ($version in $module.versions)
{
$modulePath = Join-Path -Path $installPSModulePath -ChildPath "${moduleName}_${version}"
Write-Host " - $version [$modulePath]"
try
{
Save-Module -Path $modulePath -Name $moduleName -RequiredVersion $version -Force -ErrorAction Stop
}
catch
{
Write-Host "Error: $_"
exit 1
}
}
# 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};"
}
}
# Add modules to the PSModulePath
$psModuleMachinePath += $env:PSModulePath
[Environment]::SetEnvironmentVariable("PSModulePath", $psModuleMachinePath, "Machine")