Files
runner-images-temp/images/win/scripts/Installers/Install-AzureModules.ps1
T

53 lines
1.8 KiB
PowerShell
Raw Normal View History

################################################################################
## File: Install-AzureModules.ps1
## Desc: Install Azure PowerShell modules
################################################################################
2020-07-01 15:16:01 +03:00
# The correct Modules need to be saved in C:\Modules
$installPSModulePath = $env:PSMODULES_ROOT_FOLDER
if (-not (Test-Path -LiteralPath $installPSModulePath))
{
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
}
2020-07-01 15:16:01 +03:00
# Get modules content from toolset
$modules = (Get-ToolsetContent).azureModules
2020-07-01 15:16:01 +03:00
$psModuleMachinePath = ""
2020-07-01 15:16:01 +03:00
foreach ($module in $modules)
{
2020-07-01 15:16:01 +03:00
$moduleName = $module.name
Write-Host "Installing ${moduleName} to the ${installPSModulePath} path..."
foreach ($version in $module.versions)
{
2020-07-01 15:16:01 +03:00
$modulePath = Join-Path -Path $installPSModulePath -ChildPath "${moduleName}_${version}"
Write-Host " - $version [$modulePath]"
try
{
2020-07-01 15:16:01 +03:00
Save-Module -Path $modulePath -Name $moduleName -RequiredVersion $version -Force -ErrorAction Stop
}
catch
{
2020-02-25 19:20:15 +03:00
Write-Host "Error: $_"
exit 1
}
}
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};"
}
}
2020-07-01 15:16:01 +03:00
# Add modules to the PSModulePath
$psModuleMachinePath += $env:PSModulePath
[Environment]::SetEnvironmentVariable("PSModulePath", $psModuleMachinePath, "Machine")
Invoke-PesterTests -TestFile "PowerShellModules" -TestName "AzureModules"