11# ###############################################################################
22# # File: Install-AzureModules.ps1
33# # Desc: Install Azure PowerShell modules
4+ # # Supply chain security: package manager
45# ###############################################################################
56
7+ #
8+ # prepares the environment for the Azure PowerShell modules
9+ # used by AzureFileCopy@4, AzureFileCopy@5, AzurePowerShell@4, AzurePowerShell@5 tasks
10+ #
11+
612# The correct Modules need to be saved in C:\Modules
713$installPSModulePath = " C:\\Modules"
814if (-not (Test-Path - LiteralPath $installPSModulePath ))
@@ -25,56 +31,15 @@ foreach ($module in $modules)
2531 {
2632 $modulePath = Join-Path - Path $installPSModulePath - ChildPath " ${moduleName} _${version} "
2733 Write-Host " - $version [$modulePath ]"
28- try
29- {
30- Save-Module - Path $modulePath - Name $moduleName - RequiredVersion $version - Force - ErrorAction Stop
31- }
32- catch
33- {
34- Write-Host " Error: $_ "
35- exit 1
36- }
37- }
38-
39- if ($null -ne $module.url )
40- {
41- $assets = Invoke-RestMethod $module.url
34+ Save-Module - Path $modulePath - Name $moduleName - RequiredVersion $version - Force - ErrorAction Stop
4235 }
4336
4437 foreach ($version in $module.zip_versions )
4538 {
46- # Install modules from GH Release
47- if ($null -ne $assets )
48- {
49- $asset = $assets | Where-Object version -eq $version `
50- | Select-Object - ExpandProperty files `
51- | Select-Object - First 1
52-
53- Write-Host " Installing $ ( $module.name ) $version ..."
54- if ($null -ne $asset ) {
55- Start-DownloadWithRetry - Url $asset.download_url - Name $asset.filename - DownloadPath $installPSModulePath
56- } else {
57- Write-Host " Asset was not found in versions manifest"
58- exit 1
59- }
60- }
61- # Install modules from vsts blob
62- else
63- {
64- $modulePath = Join-Path - Path $installPSModulePath - ChildPath " ${moduleName} _${version} "
65- $filename = " ${moduleName} _${version} .zip"
66- $download_url = [System.String ]::Concat($module.blob_url , $filename )
67- Write-Host " - $version [$modulePath ]"
68- try
69- {
70- Start-DownloadWithRetry - Url $download_url - Name $filename - DownloadPath $installPSModulePath
71- }
72- catch
73- {
74- Write-Host " Error: $_ "
75- exit 1
76- }
77- }
39+ $modulePath = Join-Path - Path $installPSModulePath - ChildPath " ${moduleName} _${version} "
40+ Save-Module - Path $modulePath - Name $moduleName - RequiredVersion $version - Force - ErrorAction Stop
41+ Compress-Archive - Path $modulePath - DestinationPath " ${modulePath} .zip"
42+ Remove-Item $modulePath - Recurse - Force
7843 }
7944 # Append default tool version to machine path
8045 if ($null -ne $module.default )
0 commit comments