diff --git a/Tasks/AzurePowerShell/task.json b/Tasks/AzurePowerShell/task.json index c34efcde84e3..b76a7af3a521 100644 --- a/Tasks/AzurePowerShell/task.json +++ b/Tasks/AzurePowerShell/task.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 11 + "Patch": 12 }, "demands": [ "azureps" diff --git a/Tasks/AzurePowerShell/task.loc.json b/Tasks/AzurePowerShell/task.loc.json index 447073ee5c7e..4e3d3463614a 100644 --- a/Tasks/AzurePowerShell/task.loc.json +++ b/Tasks/AzurePowerShell/task.loc.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 11 + "Patch": 12 }, "demands": [ "azureps" diff --git a/Tasks/Common/VstsAzureHelpers_/ImportFunctions.ps1 b/Tasks/Common/VstsAzureHelpers_/ImportFunctions.ps1 index 16bff2382fa4..18d1bf42c810 100644 --- a/Tasks/Common/VstsAzureHelpers_/ImportFunctions.ps1 +++ b/Tasks/Common/VstsAzureHelpers_/ImportFunctions.ps1 @@ -94,8 +94,8 @@ function Import-FromModulePath { } # Import the module. - Write-Host "##[command]Import-Module -Name $($module.Path) -Global" - $module = Import-Module -Name $module.Path -Global -PassThru + Write-Host "##[command]Import-Module -Name $($module.Path) -Global -Force" + $module = Import-Module -Name $module.Path -Global -PassThru -Force Write-Verbose "Imported module version: $($module.Version)" if ($Classic) { @@ -117,8 +117,8 @@ function Import-FromModulePath { throw (Get-VstsLocString -Key AZ_AzureRMProfileModuleNotFound) } # Import and then store the AzureRM.profile module. - Write-Host "##[command]Import-Module -Name $($profileModule.Path) -Global" - $script:azureRMProfileModule = Import-Module -Name $profileModule.Path -Global -PassThru + Write-Host "##[command]Import-Module -Name $($profileModule.Path) -Global -Force" + $script:azureRMProfileModule = Import-Module -Name $profileModule.Path -Global -PassThru -Force } else { $script:azureRMProfileModule = $profileModule } @@ -156,8 +156,8 @@ function Import-FromSdkPath { continue } # Import the module. - Write-Host "##[command]Import-Module -Name $path -Global" - $module = Import-Module -Name $path -Global -PassThru + Write-Host "##[command]Import-Module -Name $path -Global -Force" + $module = Import-Module -Name $path -Global -PassThru -Force Write-Verbose "Imported module version: $($module.Version)" # Store the imported module. if ($Classic) { @@ -197,8 +197,8 @@ function Import-AzureRmSubmodulesFromSdkPath { try { # Azure.Storage submodule needs to be imported first $azureStorageModulePath = [System.IO.Path]::Combine($programFiles, "Microsoft SDKs\Azure\PowerShell\Storage\Azure.Storage\Azure.Storage.psd1") - Write-Host "##[command]Import-Module -Name $azureStorageModulePath -Global" - $azureStorageModule = Import-Module -Name $azureStorageModulePath -Global -PassThru + Write-Host "##[command]Import-Module -Name $azureStorageModulePath -Global -Force" + $azureStorageModule = Import-Module -Name $azureStorageModulePath -Global -PassThru -Force Write-Verbose "Imported module version: $($azureStorageModule.Version)" } catch { @@ -215,8 +215,8 @@ function Import-AzureRmSubmodulesFromSdkPath { } $azureRmNestedModulePath = [System.IO.Path]::Combine($azureRmNestedModule.FullName, $azureRmNestedModule.Name + ".psd1") try { - Write-Verbose "##[command]Import-Module -Name $azureRmNestedModulePath -Global" - $azureRmSubmodule = Import-Module -Name $azureRmNestedModulePath -Global -PassThru + Write-Verbose "##[command]Import-Module -Name $azureRmNestedModulePath -Global -Force" + $azureRmSubmodule = Import-Module -Name $azureRmNestedModulePath -Global -PassThru -Force Write-Verbose "Imported module version: $($azureRmSubmodule.Version)" } catch { diff --git a/Tasks/Common/VstsAzureHelpers_/Tests/Import-FromModulePath.ImportsModules.ps1 b/Tasks/Common/VstsAzureHelpers_/Tests/Import-FromModulePath.ImportsModules.ps1 index 8e1028b0e1f9..1f9628665b7e 100644 --- a/Tasks/Common/VstsAzureHelpers_/Tests/Import-FromModulePath.ImportsModules.ps1 +++ b/Tasks/Common/VstsAzureHelpers_/Tests/Import-FromModulePath.ImportsModules.ps1 @@ -44,10 +44,10 @@ foreach ($variableSet in $variableSets) { Unregister-Mock Get-Module Unregister-Mock Import-Module Register-Mock Get-Module { $variableSet.Modules[0] } -- -Name $variableSet.Modules[0].Name -ListAvailable - Register-Mock Import-Module { $variableSet.Modules[0] } -- -Name $variableSet.Modules[0].Path -Global -PassThru + Register-Mock Import-Module { $variableSet.Modules[0] } -- -Name $variableSet.Modules[0].Path -Global -PassThru -Force if ($variableSet.Modules.Length -eq 2) { Register-Mock Get-Module { $variableSet.Modules[0] } -- -Name $variableSet.Modules[0].Name - Register-Mock Import-Module { $variableSet.Modules[1] } -- -Name $variableSet.Modules[1].Path -Global -PassThru + Register-Mock Import-Module { $variableSet.Modules[1] } -- -Name $variableSet.Modules[1].Path -Global -PassThru -Force } # Act. @@ -55,9 +55,9 @@ foreach ($variableSet in $variableSets) { # Assert. Assert-AreEqual $true $result - Assert-WasCalled Import-Module -- -Name $variableSet.Modules[0].Path -Global -PassThru + Assert-WasCalled Import-Module -- -Name $variableSet.Modules[0].Path -Global -PassThru -Force if ($variableSet.Modules.Length -eq 2) { - Assert-WasCalled Import-Module -- -Name $variableSet.Modules[1].Path -Global -PassThru + Assert-WasCalled Import-Module -- -Name $variableSet.Modules[1].Path -Global -PassThru -Force } if ($variableSet.Classic) { diff --git a/Tasks/Common/VstsAzureHelpers_/Tests/Import-FromSdkPath.ImportsModule.ps1 b/Tasks/Common/VstsAzureHelpers_/Tests/Import-FromSdkPath.ImportsModule.ps1 index e19a25e7ef1f..d185746daf6f 100644 --- a/Tasks/Common/VstsAzureHelpers_/Tests/Import-FromSdkPath.ImportsModule.ps1 +++ b/Tasks/Common/VstsAzureHelpers_/Tests/Import-FromSdkPath.ImportsModule.ps1 @@ -80,12 +80,12 @@ foreach ($variableSet in $variableSets) { # Setup Import-Module. if ($variableSet.FoundInProgramFilesX86) { $expectedModule = @{ Version = [version]'1.2.3.4' } - Register-Mock Import-Module { $expectedModule } -Name $wowPsd1 -Global -PassThru + Register-Mock Import-Module { $expectedModule } -Name $wowPsd1 -Global -PassThru -Force } if ($variableSet.FoundInProgramFiles) { $expectedModule = @{ Version = [version]'2.3.4.5' } - Register-Mock Import-Module { $expectedModule } -Name $psd1 -Global -PassThru + Register-Mock Import-Module { $expectedModule } -Name $psd1 -Global -PassThru -Force } if($variableSet.Classic -eq $false) { @@ -100,9 +100,9 @@ foreach ($variableSet in $variableSets) { # Assert. Assert-AreEqual $true $result if ($variableSet.FoundInProgramFilesX86) { - Assert-WasCalled Import-Module -- -Name $wowPsd1 -Global -PassThru + Assert-WasCalled Import-Module -- -Name $wowPsd1 -Global -PassThru -Force } else { - Assert-WasCalled Import-Module -- -Name $psd1 -Global -PassThru + Assert-WasCalled Import-Module -- -Name $psd1 -Global -PassThru -Force } if ($variableSet.Classic) {