From c9b0b24d0230cadf8aca15fd921dedc94de1ed74 Mon Sep 17 00:00:00 2001 From: markcowl Date: Thu, 8 Oct 2015 17:17:36 -0700 Subject: [PATCH 1/2] Add incompatible version check [Fixes #105258902] --- tools/AzureRM/AzureRM.psm1 | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/AzureRM/AzureRM.psm1 b/tools/AzureRM/AzureRM.psm1 index 1aa94cc1340d..4e37be5fc815 100644 --- a/tools/AzureRM/AzureRM.psm1 +++ b/tools/AzureRM/AzureRM.psm1 @@ -38,6 +38,22 @@ function Test-AdminRights([string]$Scope) } } +function CheckIncompatibleVersion([bool]$Force) +{ + $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'." + if ( Test-Path "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureResourceManager.psd1") + { + if ($Force) + { + Write-Warning $message + } + else + { + throw $message + } + } +} + function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[string]$Repository,[string]$Scope) { $_MinVer = "$MajorVersion.0.0.0" @@ -81,6 +97,7 @@ function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[str #> function Update-AzureRM { + param( [Parameter(Position=0, Mandatory = $false)] [string] @@ -91,9 +108,12 @@ function Update-AzureRM [Parameter(Position=2, Mandatory = $false)] [ValidateSet("CurrentUser","AllUsers")] [string] - $Scope = "AllUsers") + $Scope = "AllUsers", + [switch] + $Force = $false) Test-AdminRights $Scope + CheckIncompatibleVersion($Force.IsPresent) Write-Output "Installing AzureRM modules." @@ -132,7 +152,6 @@ function Import-AzureRM [Parameter(Position=0, Mandatory = $false)] [string] $MajorVersion = $AzureMajorVersion) - Write-Output "Importing AzureRM modules." $_MinVer = "$MajorVersion.0.0.0" From 115ae8810eb0146685425e258f48832d2be67eaf Mon Sep 17 00:00:00 2001 From: markcowl Date: Thu, 8 Oct 2015 17:22:04 -0700 Subject: [PATCH 2/2] Fix indentation in new script function --- tools/AzureRM/AzureRM.psm1 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/AzureRM/AzureRM.psm1 b/tools/AzureRM/AzureRM.psm1 index 4e37be5fc815..9f2c73a34b1b 100644 --- a/tools/AzureRM/AzureRM.psm1 +++ b/tools/AzureRM/AzureRM.psm1 @@ -40,18 +40,18 @@ function Test-AdminRights([string]$Scope) function CheckIncompatibleVersion([bool]$Force) { - $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'." - if ( Test-Path "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureResourceManager.psd1") - { - if ($Force) - { - Write-Warning $message - } - else - { - throw $message - } - } + $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'." + if ( Test-Path "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureResourceManager.psd1") + { + if ($Force) + { + Write-Warning $message + } + else + { + throw $message + } + } } function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[string]$Repository,[string]$Scope)