@@ -8,10 +8,18 @@ param (
88 [string ]$TestsToRun
99)
1010
11- function InstallModule ([string ]$Name , [version ]$Version ){
12- if (! (Get-Module $Name - List | where Version -ge $Version )) {
13- Write-Host " Installing $Name "
14- Install-Module - Name $Name - Force - SkipPublisherCheck - Scope CurrentUser - Repository PSGallery
11+ function InstallModule ([string ]$Name , [version ]$Version , [version ]$MaxVersion = $null ){
12+ if ($MaxVersion ) {
13+ if (! (Get-Module $Name - List | where Version -ge $Version | where Version -le $MaxVersion )) {
14+ Write-Host " Installing $Name with Max Version $MaxVersion "
15+ Install-Module - Name $Name - Force - SkipPublisherCheck - Scope CurrentUser - Repository PSGallery - MaximumVersion $MaxVersion
16+ }
17+ Import-Module $Name - MaximumVersion $MaxVersion
18+ } else {
19+ if (! (Get-Module $Name - List | where Version -ge $Version )) {
20+ Write-Host " Installing $Name "
21+ Install-Module - Name $Name - Force - SkipPublisherCheck - Scope CurrentUser - Repository PSGallery
22+ }
1523 Import-Module $Name
1624 }
1725 if ($env: TF_BUILD ) {Get-Module $Name - List}
@@ -32,7 +40,7 @@ if ($env:TF_BUILD) {
3240# Install Pester and Platy, if needed
3341#
3442
35- InstallModule Pester ' 4.0.0'
43+ InstallModule Pester ' 4.0.0' ' 4.99 '
3644InstallModule PlatyPS ' 0.14.0'
3745InstallModule PSScriptAnalyzer ' 1.17.0'
3846
@@ -53,4 +61,4 @@ switch ($TestsToRun) {
5361
5462Write-Host " Run Pester tests"
5563$Result = Invoke-Pester - Path " $tests /module" , " $tests /functions" - Tag $Tags - PassThru - OutputFile PesterTestResults.xml
56- if ($Result.failedCount -ne 0 ) {Write-Error " Pester returned errors" }
64+ if ($Result.failedCount -ne 0 ) {Write-Error " Pester returned errors" }
0 commit comments