Skip to content

Commit c9b0b24

Browse files
committed
Add incompatible version check [Fixes #105258902]
1 parent 2c6b2be commit c9b0b24

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tools/AzureRM/AzureRM.psm1

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ function Test-AdminRights([string]$Scope)
3838
}
3939
}
4040

41+
function CheckIncompatibleVersion([bool]$Force)
42+
{
43+
$message = "An incompatible version of Azure Resource Manager PowerShell cmdlets is installed. Please uninstall Microsoft Azure PowerShell using the 'Control Panel' before installing these cmdlets. To install these cmdlets regardless of compatibility issues, execute 'Install-AzureRM -Force'."
44+
if ( Test-Path "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureResourceManager.psd1")
45+
{
46+
if ($Force)
47+
{
48+
Write-Warning $message
49+
}
50+
else
51+
{
52+
throw $message
53+
}
54+
}
55+
}
56+
4157
function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[string]$Repository,[string]$Scope)
4258
{
4359
$_MinVer = "$MajorVersion.0.0.0"
@@ -81,6 +97,7 @@ function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[str
8197
#>
8298
function Update-AzureRM
8399
{
100+
84101
param(
85102
[Parameter(Position=0, Mandatory = $false)]
86103
[string]
@@ -91,9 +108,12 @@ function Update-AzureRM
91108
[Parameter(Position=2, Mandatory = $false)]
92109
[ValidateSet("CurrentUser","AllUsers")]
93110
[string]
94-
$Scope = "AllUsers")
111+
$Scope = "AllUsers",
112+
[switch]
113+
$Force = $false)
95114

96115
Test-AdminRights $Scope
116+
CheckIncompatibleVersion($Force.IsPresent)
97117

98118
Write-Output "Installing AzureRM modules."
99119

@@ -132,7 +152,6 @@ function Import-AzureRM
132152
[Parameter(Position=0, Mandatory = $false)]
133153
[string]
134154
$MajorVersion = $AzureMajorVersion)
135-
136155
Write-Output "Importing AzureRM modules."
137156

138157
$_MinVer = "$MajorVersion.0.0.0"

0 commit comments

Comments
 (0)