Skip to content

Commit 3d24778

Browse files
committed
Adding Gallery module cleanup to msi installer
1 parent 9a872b4 commit 3d24778

File tree

3 files changed

+59
-31
lines changed

3 files changed

+59
-31
lines changed

setup/Setup/RemoveGalleryModules.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
function Remove-Modules
16+
{
17+
param([string]$basePath)
18+
$paths = "Azure", "AzureRM", "AzureRM.*", "Azure.Storage"
19+
$paths | ForEach-Object {
20+
$modulePath = ([System.IO.Path]::Combine($basePath, $_))
21+
try {
22+
Write-Host Removing $_
23+
if (Test-Path $modulePath)
24+
{
25+
Remove-Item -Recurse $modulePath -Force
26+
}
27+
}
28+
catch {}
29+
}
30+
}
31+
32+
if (Test-Path 'Env:\ProgramFiles(x86)')
33+
{
34+
Remove-Module ([System.IO.Path]::Combine(${env:ProgramFiles(x86)}, "WindowsPowerShell", "Modules"))
35+
}
36+
37+
if (Test-Path Env:\ProgramFiles)
38+
{
39+
Remove-Module ([System.IO.Path]::Combine($env:ProgramFiles, "WindowsPowerShell", "Modules"))
40+
}
41+

setup/Setup/SetExecutionPolicy.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# limitations under the License.
1313
# ----------------------------------------------------------------------------------
1414

15-
1615
try
1716
{
1817
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force -ErrorAction "SilentlyContinue"

setup/azurecmd.wxs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<?define version="1.0.1" ?>
99
<?define versionedStartMenuFolder="Microsoft Azure" ?>
1010
<?define staleStartMenuFolder="Windows Azure" ?>
11-
11+
1212
<Product Id="*"
1313
Name="$(var.productName)"
1414
Language="1033"
@@ -41,27 +41,6 @@
4141

4242
<SetProperty Id="POWERSHELLEXE" Value="[WindowsFolder]System32\WindowsPowerShell\v1.0\powershell.exe" Before="AppSearch"/>
4343

44-
<Property Id="POWERSHELLGETMODULESINSTALLED" >
45-
<DirectorySearch Id="PROGRAMFILESCONTAINER" Path="[BaseModulesFolder]">
46-
<DirectorySearch Id= "PROFILEMODULE" Path="AzureRM.Profile"/>
47-
</DirectorySearch>
48-
</Property>
49-
50-
<Property Id="POWERSHELLGETAZUREINSTALLED" >
51-
<DirectorySearch Id="AZURECONTAINER" Path="[BaseModulesFolder]">
52-
<DirectorySearch Id= "AZUREMODULE" Path="Azure"/>
53-
</DirectorySearch>
54-
</Property>
55-
56-
<Condition Message="Azure Modules from the PowerShell Gallery are installed on this machine. Please remove these modules before installing this MSI.">
57-
<![CDATA[Installed or NOT(POWERSHELLGETMODULESINSTALLED >< "AzureRM.Profile")]]>
58-
</Condition>
59-
60-
<Condition Message="Azure Modules from the PowerShell Gallery are installed on this machine. Please remove these modules before installing this MSI.">
61-
<![CDATA[Installed or NOT(POWERSHELLGETAZUREINSTALLED >< "Azure")]]>
62-
</Condition>
63-
64-
6544
<Condition Message="This setup requires the Windows PowerShell 3.0 or compatible version to be installed.">
6645
<!-- This condition will break if PowerShell has version x3.0 and it is not compatible with 3.0 -->
6746
<![CDATA[Installed or (PSCOMPATIBLEVERSION >< "3.0")]]>
@@ -88,19 +67,19 @@
8867
</Directory>
8968

9069
<Property Id="POWERSHELLPATH">
91-
<RegistrySearch Id="POWERSHELLPATH"
92-
Type="raw"
93-
Root="HKLM"
94-
Key="SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine"
95-
Name="ApplicationBase" />
70+
<RegistrySearch Id="POWERSHELLPATH"
71+
Type="raw"
72+
Root="HKLM"
73+
Key="SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine"
74+
Name="ApplicationBase" />
9675
</Property>
9776

9877
<DirectoryRef Id="PowerShellFolder">
9978
<Component Id="PSModulePath.System" Guid="273525B9-7AAB-421A-90C8-8E50A1840B8D">
10079
<CreateFolder />
10180
<!-- Work around bug that PowerShell does not always consider default module paths. -->
10281
<Environment Id="PSModulePath.SystemAppRoot" Action="set" Name="PSMODULEPATH" Part="last" Value="[BaseModulesFolder];[PowerShellFolder]ResourceManager\AzureResourceManager;[PowerShellFolder]ServiceManagement" System="yes" />
103-
</Component>
82+
</Component>
10483
</DirectoryRef>
10584

10685
<DirectoryRef Id="PowerShellFolder">
@@ -109,6 +88,12 @@
10988
</Component>
11089
</DirectoryRef>
11190

91+
<DirectoryRef Id="PowerShellFolder">
92+
<Component Id="AzureSdkRemoveModulesScript" Guid="7d75fe67-88e4-40da-bc3d-874cb0438d30">
93+
<File Id="AzureSdkRemoveModulesScriptFile" KeyPath="yes" Source="$(var.SolutionDir)\Setup\RemoveGalleryModules.ps1" />
94+
</Component>
95+
</DirectoryRef>
96+
11297
<DirectoryRef Id="AzureSdkMenu">
11398
<Component Id="AzureSdkShortcut" Guid="A9B58A22-F746-451D-8840-F887D8014C3C">
11499
<Shortcut Id="AzureSdkStartMenuShortcut"
@@ -127,17 +112,20 @@
127112
<ComponentRef Id="PSModulePath.System" />
128113
<ComponentRef Id="AzureSdkShortcut" />
129114
<ComponentRef Id="AzureSdkExecutionPolicyScript" />
130-
</Feature>
115+
<ComponentRef Id="AzureSdkRemoveModulesScript" />
116+
</Feature>
131117

132118
<Binary Id="CustomActions" SourceFile="$(var.caSourceDir)\Microsoft.WindowsAzure.Setup.CA.dll"/>
133119
<CustomAction Id="UpdatePSShortcut" BinaryKey="CustomActions" DllEntry="UpdatePSShortcut" Execute ="deferred" Impersonate="no"/>
134120
<CustomAction Id="SetCustomActionDataValue" Return="check" Property="UpdatePSShortcut"
135121
Value="ShortcutPath=[AzureSdkMenu]Microsoft Azure PowerShell.lnk;DefaultShortcutPath=[ProgramMenuFolder]System Tools\Windows PowerShell.lnk" />
136122
<CustomAction Id="SetExecutionPolicy" Property="POWERSHELLEXE" ExeCommand="-NoLogo -NoProfile -ExecutionPolicy Bypass -Command &quot;. \&quot;[PowerShellFolder]SetExecutionPolicy.ps1\&quot;&quot;" Execute="deferred" Impersonate="no" Return="check"/>
123+
<CustomAction Id="RemoveGalleryModules" Property="POWERSHELLEXE" ExeCommand="-NoLogo -NoProfile -ExecutionPolicy Bypass -Command &quot;. \&quot;[PowerShellFolder]RemoveGalleryModules.ps1\&quot;&quot;" Execute="deferred" Impersonate="no" Return="check"/>
137124

138125
<InstallExecuteSequence>
139126
<Custom Action="SetCustomActionDataValue" After="CreateShortcuts">NOT Installed</Custom>
140-
<Custom Action="UpdatePSShortcut" After="SetCustomActionDataValue">NOT Installed</Custom>
127+
<Custom Action="RemoveGalleryModules" After="SetCustomActionDataValue">NOT Installed</Custom>
128+
<Custom Action="UpdatePSShortcut" After="RemoveGalleryModules">NOT Installed</Custom>
141129
<Custom Action="SetExecutionPolicy" After="UpdatePSShortcut">NOT Installed</Custom>
142130
</InstallExecuteSequence>
143131

0 commit comments

Comments
 (0)