Files
runner-images/images/win/scripts/Installers/Install-AzureModules.ps1
Mikhail Timofeev 23aade159c Replace current validates with pester testing approach #1 (#1253)
* first part

* fix session manager plugin

* rework AWS installation

* azure cosmos db tests

* azure devops cli

* add azmodules test

* put brackets

* add root folder

* remove validate aliyun

* add azure modules

* update modules test

* docker, baze, dotnetsdk

* DACFx

* add azdevopscli

* change to Should -BeTrue

* nitpicks

* remove extra

* add azurecli

* remove BeforeAll for DACFx

* a bit of refactoring

* fix templates

* remove disk space validation

* rename to powershell modules

* fix templates
2020-07-21 09:50:01 +03:00

57 lines
1.9 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")
Invoke-PesterTests -TestFile "PowerShellModules" -TestName "AzureModules"