Skip to content

Commit 052dd56

Browse files
author
Hovsep
committed
Merge pull request Azure#995 from hovsepm/dev
[#103630362] Fixed uninstaller and added Admin role validation
2 parents 8f4f725 + 25fee83 commit 052dd56

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

tools/AzureRM/AzureRM.psd1

0 Bytes
Binary file not shown.

tools/AzureRM/AzureRM.psm1

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
#Requires -RunAsAdministrator
2-
31
$AzureRMProfileVersion = "0.9.8";
42

53
$AzureRMModules = @{
6-
"Azure.Storage" = "0.9.8";
74
"AzureRM.ApiManagement" = "0.9.8";
85
"AzureRM.Automation" = "0.9.8";
96
"AzureRM.Backup" = "0.9.8";
@@ -16,7 +13,6 @@ $AzureRMModules = @{
1613
"AzureRM.KeyVault" = "0.9.8";
1714
"AzureRM.Network" = "0.9.8";
1815
"AzureRM.OperationalInsights" = "0.9.8";
19-
"AzureRM.Profile" = "0.9.8";
2016
"AzureRM.RedisCache" = "0.9.8";
2117
"AzureRM.Resources" = "0.9.8";
2218
"AzureRM.SiteRecovery" = "0.9.8";
@@ -29,6 +25,19 @@ $AzureRMModules = @{
2925
"AzureRM.Websites" = "0.9.8"
3026
}
3127

28+
function Validate-AdminRights([string]$Scope)
29+
{
30+
if ($Scope -ne "CurrentUser")
31+
{
32+
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
33+
$isAdmin = (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
34+
if($isAdmin -eq $false)
35+
{
36+
throw "Administrator rights are required to install Microsoft Azure modules"
37+
}
38+
}
39+
}
40+
3241
function Import-ModuleWithVersionCheck([string]$Name,[string]$MinimumVersion,[string]$Repository,[string]$Scope)
3342
{
3443
$minVer = $MinimumVersion
@@ -77,6 +86,8 @@ function Update-AzureRM
7786
$Scope = "AllUsers"
7887
}
7988

89+
Validate-AdminRights $Scope
90+
8091
Write-Output "Installing AzureRM modules."
8192

8293
Import-ModuleWithVersionCheck "AzureRM.Profile" $AzureRMProfileVersion $Repository $Scope
@@ -103,18 +114,24 @@ function Uninstall-AzureRM
103114
[string]
104115
$Repository)
105116

117+
Validate-AdminRights "AllUsers"
118+
106119
Write-Output "Uninstalling AzureRM modules."
107120

108121
$AzureRMModules.Keys | ForEach {
109122
$moduleName = $_
110123
if ((Get-InstalledModule | where {$_.Name -eq $moduleName}) -ne $null) {
111-
Uninstall-Module -Name $_ -ErrorAction Stop
124+
$minVer = $AzureRMModules[$_]
125+
$maxVer = "$($minVer.Split(".")[0]).9999.0"
126+
Uninstall-Module -Name $_ -MinimumVersion $minVer -MaximumVersion $maxVer -ErrorAction Stop
112127
Write-Output "$moduleName uninstalled..."
113128
}
114129
}
115130

116-
if ((Get-InstalledModule | where {"AzureRM.Profile" -eq $moduleName}) -ne $null) {
117-
Uninstall-Module -Name "AzureRM.Profile" -ErrorAction Stop
131+
if ((Get-InstalledModule | where {$_.Name -eq "AzureRM.Profile"}) -ne $null) {
132+
$minVer = $AzureRMProfileVersion
133+
$maxVer = "$($minVer.Split(".")[0]).9999.0"
134+
Uninstall-Module -Name "AzureRM.Profile" -MinimumVersion $minVer -MaximumVersion $maxVer -ErrorAction Stop
118135
Write-Output "AzureRM.Profile uninstalled..."
119136
}
120137
}

0 commit comments

Comments
 (0)