From 98d05de2e819dbe7c1d20e7a2f8e1907cf744946 Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Tue, 25 Feb 2020 19:20:15 +0300 Subject: [PATCH 1/6] add Az 3.5.0 --- .../Installers/Install-AzureModules.ps1 | 231 ++++-------------- .../Installers/Validate-AzureModules.ps1 | 130 ++++++---- 2 files changed, 132 insertions(+), 229 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureModules.ps1 b/images/win/scripts/Installers/Install-AzureModules.ps1 index 0721e6e9a..c8a20c414 100644 --- a/images/win/scripts/Installers/Install-AzureModules.ps1 +++ b/images/win/scripts/Installers/Install-AzureModules.ps1 @@ -3,195 +3,66 @@ ## Desc: Install Azure PowerShell modules ################################################################################ -Add-Type -AssemblyName System.IO.Compression.FileSystem - -function Download-Zip -{ - [CmdletBinding()] - Param( - [Parameter( - Mandatory = $true - )] - [string] - $BlobUri - ) - - Write-Host "Downloading the zip from blob: '$BlobUri'" - $fileName = "azureps_" + "$(Get-Random)" + ".zip" - $targetLocation = Join-Path $ENV:Temp -ChildPath $fileName - Write-Host "Download target location: '$targetLocation'" - $webClient = New-Object Net.WebClient - $null = $webClient.DownloadFileAsync($BlobUri, $targetLocation) - while ($webClient.IsBusy) { } - Write-Host "Download complete. Target Location: '$targetLocation'" - return $targetLocation -} - -function Extract-Zip -{ - [CmdletBinding()] - Param( - [Parameter( - Mandatory = $true - )] - [string] - $ZipFilePath, - - [Parameter( - Mandatory = $true - )] - [string] - $TargetLocation - ) - - Write-Host "Expanding the Zip File: '$ZipFilePath'. Target: '$TargetLocation'" - $null = [System.IO.Compression.ZipFile]::ExtractToDirectory($ZipFilePath, $TargetLocation) - Write-Host "Extraction completed successfully." -} - Set-PSRepository -InstallationPolicy Trusted -Name PSGallery -# We try to detect the whether Azure PowerShell is installed using .msi file. If it is installed, we find it's version, then it needs to be uninstalled manually (because the uninstallation requires the PowerShell session to be closed) -$regKey = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" -$installedApplications = Get-ItemProperty -Path $regKey -$SdkVersion = ($installedApplications | Where-Object { $_.DisplayName -and $_.DisplayName.toLower().Contains("microsoft azure powershell") } | Select-Object -First 1).DisplayVersion - -if($SdkVersion -eq $null) -{ - Write-Host "No .msi Installation Present" -} -else -{ - Write-Host "An Azure PowerShell Installation through installer has been detected. Please close this powershell session and manually uninstall the Azure PowerShell from the Add or Remove Programs in the Control Panel. Then, rerun this script from an Admin PowerShell" - throw "An Azure PowerShell Installation through installer has been detected. Please close this powershell session and manually uninstall the Azure PowerShell from the Add or Remove Programs in the Control Panel. Then, rerun this script from an Admin PowerShell" -} - -# We will try to uninstall any installation of Azure PowerShell - -$modules = Get-Module -Name Azure -ListAvailable -Write-Host "The Azure Modules initially present are:" -$modules | Select-Object Name,Version,Path | Format-Table - -foreach($module in $modules) -{ - # add logging for telling what module we are working on now - if(Test-Path -LiteralPath $module.Path) - { - try - { - Uninstall-Module -Name Azure -RequiredVersion $module.Version.tostring() -Force - } - catch - { - Write-Host "The Uninstallation of Azure Module version: $($module.Version.tostring()) failed with the error: $($_.Exception.Message) . Please Check if there isn't any other PowerShell session open." - throw $_.Exception.Message - } - } -} - -$modules = Get-Module -Name AzureRM -ListAvailable -Write-Host "The AzureRM Modules initially present are:" -$modules | Select-Object Name,Version,Path | Format-Table - -foreach($module in $modules) -{ - # add logging for telling what module we are working on now - if(Test-Path -LiteralPath $module.Path) - { - try - { - Uninstall-Module -Name AzureRM -RequiredVersion $module.Version.tostring() -Force - } - catch - { - Write-Host "The Uninstallation of AzureRM Module version: $($module.Version.tostring()) failed with the error: $($_.Exception.Message) . Please Check if there isn't any other PowerShell session open." - throw $_.Exception.Message - } - } -} - -#after this, the only installations available through a Get-Module cmdlet should be nothing - -$modules = Get-Module -Name Azure -ListAvailable - -foreach($module in $modules) -{ - Write-Host "Module found: $($module.Name) Module Version: $($module.Version)" - if($module.Version.ToString() -ne " ") - { - Write-Host "Another installation of Azure module is detected with version $($module.Version.ToString()) at path: $($module.Path)" - throw "Azure module uninstallation unsuccessful" - } -} - -$modules = Get-Module -Name AzureRM -ListAvailable - -foreach($module in $modules) -{ - write-host "Module found: $($module.Name) Module Version: $($module.Version)" - if($module.Version.ToString() -ne " ") - { - Write-Host "Another installation of AzureRM module is detected with version $($module.Version.ToString()) at path: $($module.Path)" - throw "AzureRM module uninstallation unsuccessful" - } -} - #### NOW The correct Modules need to be saved in C:\Modules - -if($(Test-Path -LiteralPath "C:\Modules") -eq $true) +$installPSModulePath = 'C:\Modules' +if(-not (Test-Path -LiteralPath $installPSModulePath)) { - Write-Host "C:\Modules directory is already present. Beginning to clear it up completely" - Remove-Item -Path "C:\Modules" -Recurse -Force + Write-Host "Creating '$installPSModulePath' folder to store PowerShell Azure modules" + $null = New-Item -Path $installPSModulePath -ItemType Directory } -mkdir "C:\Modules" +# Powershell Azure modules to install +$psAzureModulesToInstall = @{ + "azurerm" = @( + "2.1.0" + "3.8.0" + "4.2.1" + "5.1.1" + "6.7.0" + "6.13.1" + ) -$directoryListing = Get-ChildItem -Path "C:\Modules" + "azure" = @( + "2.1.0" + "3.8.0" + "4.2.1" + "5.1.1" + "5.3.0" + ) -if($directoryListing.Length -gt 0) + "az" = @( + "1.0.0" + "1.6.0" + "2.3.2" + "2.6.0" + "3.1.0" + "3.5.0" + ) +} + +# Download Azure PowerShell modules +foreach($psmoduleName in $psAzureModulesToInstall.Keys) { - Write-Host "C:\Modules was not deleted properly. It still has the following contents:" - $directoryListing -} -else { - Write-Host "The Directory is clean. There are no contents present in it" -} - -# Download and unzip the stored AzurePSModules from the vstsagentools public blob -$extractLocation = "C:\Modules" -$azurePsUri = @( - "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/AzurePSModules.M157.20190808.27979.zip", - "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/AzureRmPSModules.M157.20190808.27379.zip", - "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/AzPSModules.M163.20191211.17769.zip" -) - -$azureRMModulePath = "C:\Modules\azurerm_2.1.0" -$azureModulePath = "C:\Modules\azure_2.1.0" -$finalPath = "" -$environmentPSModulePath = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine") -$existingPaths = $environmentPSModulePath -split ';' -replace '\\$','' - -if ($existingPaths -notcontains $azureRMModulePath) { - $finalPath = $azureRMModulePath -} - -if ($existingPaths -notcontains $azureModulePath) { - if($finalPath -ne "") { - $finalPath = $finalPath + ";" + $azureModulePath - } - else { - $finalPath = $azureModulePath + Write-Host "Installing '$psmoduleName' to the '$installPSModulePath' path:" + $psmoduleVersions = $psAzureModulesToInstall[$psmoduleName] + foreach($psmoduleVersion in $psmoduleVersions) + { + $psmodulePath = Join-Path $installPSModulePath "${psmoduleName}_${psmoduleVersion}" + Write-Host " - $psmoduleVersion [$psmodulePath]" + try + { + Save-Module -Path $psmodulePath -Name $psmoduleName -RequiredVersion $psmoduleVersion -Force -err + } + catch + { + Write-Host "Error: $_" + exit 1 + } } } -if($finalPath -ne "") { - [Environment]::SetEnvironmentVariable("PSModulePath", $finalPath + ";" + $env:PSModulePath, "Machine") -} - -$env:PSModulePath = $env:PSModulePath.TrimStart(';') - -foreach ($uri in $azurePsUri) -{ - $targetFile = Download-Zip -BlobUri $uri - Extract-Zip -ZipFilePath $targetFile -TargetLocation $extractLocation -} +# Add AzureRM and Azure modules to the PSModulePath +$finalModulePath = '{0};{1};{2}' -f "${installPSModulePath}\azurerm_6.13.1", "${installPSModulePath}\azure_5.3.0", $env:PSModulePath +[Environment]::SetEnvironmentVariable("PSModulePath", $finalModulePath, "Machine") \ No newline at end of file diff --git a/images/win/scripts/Installers/Validate-AzureModules.ps1 b/images/win/scripts/Installers/Validate-AzureModules.ps1 index 6927cce69..766ea08c0 100644 --- a/images/win/scripts/Installers/Validate-AzureModules.ps1 +++ b/images/win/scripts/Installers/Validate-AzureModules.ps1 @@ -5,67 +5,99 @@ Import-Module -Name ImageHelpers -Force -$DefaultModule = Get-Module -Name AzureRM -ListAvailable | Select-Object -First 1 - -$env:PSModulePath = $env:PSModulePath + ";C:\Modules" - -$azureModules = Get-Module -Name Azure -ListAvailable | Select-Object Name,Version,Path | Format-Table | Out-String - -Write-Host "The Azure Modules finally present are:" -$azureModules - -if( ($azureModules -match "2.1.0") -and ($azureModules -match "3.8.0") -and ($azureModules -match "4.2.1") -and ($azureModules -match "5.1.1")) -{ - Write-Host "Required Azure modules are present" -} -else { - Write-Host "One or more required Azure modules are not present" - throw "One or more required Azure modules are not present." -} - - -$azureRMModules = Get-Module -Name AzureRM -ListAvailable | Select-Object Name,Version,Path | Format-Table | Out-String - -Write-Host "The AzureRM Modules finally present are:" -$azureRMModules - -if( ($azureRMModules -match "2.1.0") -and ($azureRMModules -match "3.8.0") -and ($azureRMModules -match "4.2.1") -and ($azureRMModules -match "5.1.1")) -{ - Write-Host "Required AzureRM modules are present" - -} -else { - Write-Host "One or more required AzureRM modules are not present" - throw "One or more required AzureRM modules are not present." -} - - -$azureModules = Get-Module -Name AzureRM -ListAvailable - - # Adding description of the software to Markdown -$SoftwareName = "Azure/AzureRM Powershell modules" +function Add-ModuleDescription +{ + param($DefaultModule, [String]$ModuleName) -$Description = @" + # Adding description of the software to Markdown + $SoftwareName = "$ModuleName PowerShell module" + + if ($DefaultModule) + { + $Description = @" #### $($DefaultModule.Version) This version is installed and is available via ``Get-Module -ListAvailable`` "@ - -Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description - -foreach( $module in $azureModules) -{ - if($module.Version -ne $DefaultModule.Version) + } + else { + $Description = "" + } - $CurrentModule = @" + Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description + if($ModuleName -eq 'Az') + { + $azureModules = Get-ChildItem C:\Modules\az_*\Az\*\*.psd1 | Select @{n="Version";e={[Version]$_.Directory.Name}},@{n="Path";e={$_.FullName}} + } + else + { + $azureModules = Get-Module -Name $ModuleName -ListAvailable | Sort-Object Version -Unique + } + foreach($module in $azureModules) + { + if($module.Version -ne $DefaultModule.Version) + { + + $CurrentModule = @" #### $($module.Version) This version is saved but not installed _Location:_ $($module.Path) - "@ - Add-ContentToMarkdown -Content $CurrentModule + Add-ContentToMarkdown -Content $CurrentModule + } } } + +function Validate-AzureModule +{ + param([String]$ModuleName, [String[]]$ModuleVersions) + + if ($ModuleName -eq 'Az') + { + $installedVersions = Get-ChildItem C:\Modules\az_*\Az\* -Name + $prop = @{n="Name";e={"Az"}},@{n="Version";e={[Version]$_.Directory.Name}},@{n="Path";e={$_.FullName}} + $azureModules = Get-ChildItem C:\Modules\az_*\Az\*\*.psd1 | Select $prop + } + else + { + $azureModules = Get-Module -Name $ModuleName -ListAvailable + $installedVersions = $azureModules | Foreach-Object {$_.Version.ToString()} + } + + Write-Host "The $ModuleName module finally present are:" + $azureModules | Select-Object Name,Version,Path | Format-Table | Out-String + + foreach($version in $ModuleVersions) + { + if ($installedVersions -notcontains $version) + { + Write-Host "Required '$ModuleName' module '$version' version is not present" + exit 1 + } + } +} + +# Get default modules version +$defaultAzureRMModule = Get-Module -Name AzureRM -ListAvailable +$defaultAzureModule = Get-Module -Name Azure -ListAvailable + +# Add modules to the PSModulePath +$env:PSModulePath = $env:PSModulePath + ";C:\Modules" + +# Validate Azure modules and versions +$azurermVersions = "2.1.0", "3.8.0", "4.2.1", "5.1.1", "6.7.0", "6.13.1" +Validate-AzureModule -ModuleName AzureRM -ModuleVersions $azurermVersions + +$azureVersions = "2.1.0", "3.8.0", "4.2.1", "5.1.1", "5.3.0" +Validate-AzureModule -ModuleName Azure -ModuleVersions $azureVersions + +$azVersions = "1.0.0", "1.6.0", "2.3.2", "2.6.0", "3.1.0", "3.5.0" +Validate-AzureModule -ModuleName Az -ModuleVersions $azVersions + +# Adding description of the software to Markdown +Add-ModuleDescription -DefaultModule $defaultAzureRMModule -ModuleName AzureRM +Add-ModuleDescription -DefaultModule $defaultAzureModule -ModuleName Azure +Add-ModuleDescription -ModuleName Az \ No newline at end of file From 3e296589c0681c819eab9bc395bee844b8c58e0b Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Wed, 26 Feb 2020 09:03:07 +0300 Subject: [PATCH 2/6] add az 3.5.0 --- images/win/scripts/Installers/Install-AzureModules.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-AzureModules.ps1 b/images/win/scripts/Installers/Install-AzureModules.ps1 index c8a20c414..85dfd264d 100644 --- a/images/win/scripts/Installers/Install-AzureModules.ps1 +++ b/images/win/scripts/Installers/Install-AzureModules.ps1 @@ -53,7 +53,7 @@ foreach($psmoduleName in $psAzureModulesToInstall.Keys) Write-Host " - $psmoduleVersion [$psmodulePath]" try { - Save-Module -Path $psmodulePath -Name $psmoduleName -RequiredVersion $psmoduleVersion -Force -err + Save-Module -Path $psmodulePath -Name $psmoduleName -RequiredVersion $psmoduleVersion -Force -ErrorAction Stop } catch { From 5bdec625a3f0d1b075e788f3ab806039d6d47b11 Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Wed, 26 Feb 2020 10:52:48 +0300 Subject: [PATCH 3/6] add az 3.5.0 --- images/win/scripts/Installers/Install-AzureModules.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-AzureModules.ps1 b/images/win/scripts/Installers/Install-AzureModules.ps1 index 85dfd264d..5a67584a1 100644 --- a/images/win/scripts/Installers/Install-AzureModules.ps1 +++ b/images/win/scripts/Installers/Install-AzureModules.ps1 @@ -64,5 +64,5 @@ foreach($psmoduleName in $psAzureModulesToInstall.Keys) } # Add AzureRM and Azure modules to the PSModulePath -$finalModulePath = '{0};{1};{2}' -f "${installPSModulePath}\azurerm_6.13.1", "${installPSModulePath}\azure_5.3.0", $env:PSModulePath +$finalModulePath = '{0};{1};{2}' -f "${installPSModulePath}\azurerm_2.1.0", "${installPSModulePath}\azure_2.1.0", $env:PSModulePath [Environment]::SetEnvironmentVariable("PSModulePath", $finalModulePath, "Machine") \ No newline at end of file From 9933a3934c44fb49e0a1d16122ecc46ee9d2534a Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Wed, 26 Feb 2020 11:07:19 +0300 Subject: [PATCH 4/6] add az 3.5.0 --- .../win/scripts/Installers/Validate-AzureModules.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/images/win/scripts/Installers/Validate-AzureModules.ps1 b/images/win/scripts/Installers/Validate-AzureModules.ps1 index 766ea08c0..58810ba61 100644 --- a/images/win/scripts/Installers/Validate-AzureModules.ps1 +++ b/images/win/scripts/Installers/Validate-AzureModules.ps1 @@ -29,12 +29,14 @@ This version is installed and is available via ``Get-Module -ListAvailable`` Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description if($ModuleName -eq 'Az') { - $azureModules = Get-ChildItem C:\Modules\az_*\Az\*\*.psd1 | Select @{n="Version";e={[Version]$_.Directory.Name}},@{n="Path";e={$_.FullName}} + $prop = @{n="Version";e={[Version]$_.Directory.Name}},@{n="Path";e={$_.FullName}} + $azureModules = Get-ChildItem C:\Modules\az_*\Az\*\Az.psd1 | Select-Object $prop } else { $azureModules = Get-Module -Name $ModuleName -ListAvailable | Sort-Object Version -Unique } + foreach($module in $azureModules) { if($module.Version -ne $DefaultModule.Version) @@ -57,16 +59,16 @@ function Validate-AzureModule if ($ModuleName -eq 'Az') { - $installedVersions = Get-ChildItem C:\Modules\az_*\Az\* -Name $prop = @{n="Name";e={"Az"}},@{n="Version";e={[Version]$_.Directory.Name}},@{n="Path";e={$_.FullName}} - $azureModules = Get-ChildItem C:\Modules\az_*\Az\*\*.psd1 | Select $prop + $azureModules = Get-ChildItem C:\Modules\az_*\Az\*\Az.psd1 | Select-object $prop } else { $azureModules = Get-Module -Name $ModuleName -ListAvailable - $installedVersions = $azureModules | Foreach-Object {$_.Version.ToString()} } + $installedVersions = $azureModules | Foreach-Object {$_.Version.ToString()} + Write-Host "The $ModuleName module finally present are:" $azureModules | Select-Object Name,Version,Path | Format-Table | Out-String From 6830fc14d513895d1048fe1972765e1937567329 Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Wed, 26 Feb 2020 12:41:00 +0300 Subject: [PATCH 5/6] add az 3.5.0 --- .../scripts/Installers/Validate-AzureModules.ps1 | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/images/win/scripts/Installers/Validate-AzureModules.ps1 b/images/win/scripts/Installers/Validate-AzureModules.ps1 index 58810ba61..5ec111a98 100644 --- a/images/win/scripts/Installers/Validate-AzureModules.ps1 +++ b/images/win/scripts/Installers/Validate-AzureModules.ps1 @@ -15,11 +15,7 @@ function Add-ModuleDescription if ($DefaultModule) { - $Description = @" -#### $($DefaultModule.Version) - -This version is installed and is available via ``Get-Module -ListAvailable`` -"@ + $Description = "#### $($DefaultModule.Version)`n`nThis version is installed and is available via ``Get-Module -ListAvailable``" } else { @@ -42,12 +38,7 @@ This version is installed and is available via ``Get-Module -ListAvailable`` if($module.Version -ne $DefaultModule.Version) { - $CurrentModule = @" -#### $($module.Version) - -This version is saved but not installed -_Location:_ $($module.Path) -"@ + $CurrentModule = "#### $($module.Version)`n`nThis version is saved but not installed`n_Location:_ $($module.Path)" Add-ContentToMarkdown -Content $CurrentModule } } From c984fef291b677e33dabd5acc4676885a84aae0f Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Thu, 27 Feb 2020 12:58:03 +0300 Subject: [PATCH 6/6] add az 3.5.0 windows --- .../Installers/Validate-AzureModules.ps1 | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/images/win/scripts/Installers/Validate-AzureModules.ps1 b/images/win/scripts/Installers/Validate-AzureModules.ps1 index 5ec111a98..a7be9ef11 100644 --- a/images/win/scripts/Installers/Validate-AzureModules.ps1 +++ b/images/win/scripts/Installers/Validate-AzureModules.ps1 @@ -11,35 +11,35 @@ function Add-ModuleDescription param($DefaultModule, [String]$ModuleName) # Adding description of the software to Markdown - $SoftwareName = "$ModuleName PowerShell module" + $softwareName = "$moduleName PowerShell module" - if ($DefaultModule) + if ($defaultModule) { - $Description = "#### $($DefaultModule.Version)`n`nThis version is installed and is available via ``Get-Module -ListAvailable``" + $description = "#### $($defaultModule.Version)`n`nThis version is installed and is available via ``Get-Module -ListAvailable``" } else { $Description = "" } - Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description - if($ModuleName -eq 'Az') + Add-SoftwareDetailsToMarkdown -SoftwareName $softwareName -DescriptionMarkdown $description + if($moduleName -eq 'Az') { $prop = @{n="Version";e={[Version]$_.Directory.Name}},@{n="Path";e={$_.FullName}} $azureModules = Get-ChildItem C:\Modules\az_*\Az\*\Az.psd1 | Select-Object $prop } else { - $azureModules = Get-Module -Name $ModuleName -ListAvailable | Sort-Object Version -Unique + $azureModules = Get-Module -Name $moduleName -ListAvailable | Sort-Object Version -Unique } foreach($module in $azureModules) { - if($module.Version -ne $DefaultModule.Version) + if($module.Version -ne $defaultModule.Version) { - $CurrentModule = "#### $($module.Version)`n`nThis version is saved but not installed`n_Location:_ $($module.Path)" - Add-ContentToMarkdown -Content $CurrentModule + $currentModule = "#### $($module.Version)`n`nThis version is saved but not installed`n_Location:_ $($module.Path)" + Add-ContentToMarkdown -Content $currentModule } } } @@ -48,37 +48,30 @@ function Validate-AzureModule { param([String]$ModuleName, [String[]]$ModuleVersions) - if ($ModuleName -eq 'Az') + foreach($moduleVersion in $moduleVersions) { - $prop = @{n="Name";e={"Az"}},@{n="Version";e={[Version]$_.Directory.Name}},@{n="Path";e={$_.FullName}} - $azureModules = Get-ChildItem C:\Modules\az_*\Az\*\Az.psd1 | Select-object $prop - } - else - { - $azureModules = Get-Module -Name $ModuleName -ListAvailable - } + $modulePath = "${installPSModulePath}\${moduleName}_${moduleVersion}" + # Import each module in PowerShell session + $job = Start-Job -ScriptBlock { + param($modulePath, $moduleName) - $installedVersions = $azureModules | Foreach-Object {$_.Version.ToString()} - - Write-Host "The $ModuleName module finally present are:" - $azureModules | Select-Object Name,Version,Path | Format-Table | Out-String - - foreach($version in $ModuleVersions) - { - if ($installedVersions -notcontains $version) + $env:PsModulePath = "$modulePath;$env:PsModulePath" + Import-Module -Name $moduleName + Get-Module -Name $moduleName + } -ArgumentList $modulePath, $moduleName + $isError = $job | Wait-Job | Foreach-Object ChildJobs | Where-Object {$_.Error} + if($isError) { - Write-Host "Required '$ModuleName' module '$version' version is not present" + Write-Host "Required '$moduleName' module '$moduleVersion' version is not present" exit 1 } + $job | Receive-Job | Select-Object Name,Version,Path + Remove-Job $job } } -# Get default modules version -$defaultAzureRMModule = Get-Module -Name AzureRM -ListAvailable -$defaultAzureModule = Get-Module -Name Azure -ListAvailable - -# Add modules to the PSModulePath -$env:PSModulePath = $env:PSModulePath + ";C:\Modules" +# Modules path +$installPSModulePath = 'C:\Modules' # Validate Azure modules and versions $azurermVersions = "2.1.0", "3.8.0", "4.2.1", "5.1.1", "6.7.0", "6.13.1" @@ -90,6 +83,13 @@ Validate-AzureModule -ModuleName Azure -ModuleVersions $azureVersions $azVersions = "1.0.0", "1.6.0", "2.3.2", "2.6.0", "3.1.0", "3.5.0" Validate-AzureModule -ModuleName Az -ModuleVersions $azVersions +# Get default modules version +$defaultAzureRMModule = Get-Module -Name AzureRM -ListAvailable +$defaultAzureModule = Get-Module -Name Azure -ListAvailable + +# Add modules to the PSModulePath +$env:PSModulePath = $env:PSModulePath + ";C:\Modules" + # Adding description of the software to Markdown Add-ModuleDescription -DefaultModule $defaultAzureRMModule -ModuleName AzureRM Add-ModuleDescription -DefaultModule $defaultAzureModule -ModuleName Azure