Skip to content

Commit 2163773

Browse files
committed
Merge pull request #1403 from markcowl/galleryclean
Update installer to clean up gallery modules [#108777558]
2 parents f457039 + 9ff3705 commit 2163773

File tree

3 files changed

+64
-33
lines changed

3 files changed

+64
-33
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-Modules ([System.IO.Path]::Combine(${env:ProgramFiles(x86)}, "WindowsPowerShell", "Modules"))
35+
}
36+
37+
if (Test-Path Env:\ProgramFiles)
38+
{
39+
Remove-Modules ([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: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
2+
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
33

44
<?define productName="Microsoft Azure PowerShell - November 2015" ?>
55
<?define sourceDir="$(var.SolutionDir)..\src\Package\$(var.Configuration)" ?>
@@ -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"
@@ -40,27 +40,9 @@
4040
</SetProperty>
4141

4242
<SetProperty Id="POWERSHELLEXE" Value="[WindowsFolder]System32\WindowsPowerShell\v1.0\powershell.exe" Before="AppSearch"/>
43-
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-
43+
44+
<util:CloseApplication Id="ClosePowerShellExe" Target="powershell.exe" ElevatedCloseMessage="yes" CloseMessage="yes" PromptToContinue="yes" Description="PowerShell must be closed to continue with this installation. Please close any PowerShell windows and click 'Retry', or click 'Cancel' to stop installation. If you click 'Ignore' the installer will attempt to close any open PowerShell window."/>
45+
<util:CloseApplication Id="ClosePowerShellIseExe" Target="powershell_ise.exe" ElevatedCloseMessage="yes" CloseMessage="yes" PromptToContinue="yes" Description="PowerShell ISE must be closed to continue with this installation. Please close any PowerShell ISE windows and click 'Retry', or click 'Cancel' to stop installation. If you click 'Ignore' the installer will attempt to close any open PowerShell ISE window."/>
6446

6547
<Condition Message="This setup requires the Windows PowerShell 3.0 or compatible version to be installed.">
6648
<!-- This condition will break if PowerShell has version x3.0 and it is not compatible with 3.0 -->
@@ -88,19 +70,19 @@
8870
</Directory>
8971

9072
<Property Id="POWERSHELLPATH">
91-
<RegistrySearch Id="POWERSHELLPATH"
92-
Type="raw"
93-
Root="HKLM"
94-
Key="SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine"
95-
Name="ApplicationBase" />
73+
<RegistrySearch Id="POWERSHELLPATH"
74+
Type="raw"
75+
Root="HKLM"
76+
Key="SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine"
77+
Name="ApplicationBase" />
9678
</Property>
9779

9880
<DirectoryRef Id="PowerShellFolder">
9981
<Component Id="PSModulePath.System" Guid="273525B9-7AAB-421A-90C8-8E50A1840B8D">
10082
<CreateFolder />
10183
<!-- Work around bug that PowerShell does not always consider default module paths. -->
10284
<Environment Id="PSModulePath.SystemAppRoot" Action="set" Name="PSMODULEPATH" Part="last" Value="[BaseModulesFolder];[PowerShellFolder]ResourceManager\AzureResourceManager;[PowerShellFolder]ServiceManagement" System="yes" />
103-
</Component>
85+
</Component>
10486
</DirectoryRef>
10587

10688
<DirectoryRef Id="PowerShellFolder">
@@ -109,6 +91,12 @@
10991
</Component>
11092
</DirectoryRef>
11193

94+
<DirectoryRef Id="PowerShellFolder">
95+
<Component Id="AzureSdkRemoveModulesScript" Guid="7d75fe67-88e4-40da-bc3d-874cb0438d30">
96+
<File Id="AzureSdkRemoveModulesScriptFile" KeyPath="yes" Source="$(var.SolutionDir)\Setup\RemoveGalleryModules.ps1" />
97+
</Component>
98+
</DirectoryRef>
99+
112100
<DirectoryRef Id="AzureSdkMenu">
113101
<Component Id="AzureSdkShortcut" Guid="A9B58A22-F746-451D-8840-F887D8014C3C">
114102
<Shortcut Id="AzureSdkStartMenuShortcut"
@@ -127,17 +115,20 @@
127115
<ComponentRef Id="PSModulePath.System" />
128116
<ComponentRef Id="AzureSdkShortcut" />
129117
<ComponentRef Id="AzureSdkExecutionPolicyScript" />
130-
</Feature>
118+
<ComponentRef Id="AzureSdkRemoveModulesScript" />
119+
</Feature>
131120

132121
<Binary Id="CustomActions" SourceFile="$(var.caSourceDir)\Microsoft.WindowsAzure.Setup.CA.dll"/>
133122
<CustomAction Id="UpdatePSShortcut" BinaryKey="CustomActions" DllEntry="UpdatePSShortcut" Execute ="deferred" Impersonate="no"/>
134123
<CustomAction Id="SetCustomActionDataValue" Return="check" Property="UpdatePSShortcut"
135124
Value="ShortcutPath=[AzureSdkMenu]Microsoft Azure PowerShell.lnk;DefaultShortcutPath=[ProgramMenuFolder]System Tools\Windows PowerShell.lnk" />
136-
<CustomAction Id="SetExecutionPolicy" Property="POWERSHELLEXE" ExeCommand="-NoLogo -NoProfile -ExecutionPolicy Bypass -Command &quot;. \&quot;[PowerShellFolder]SetExecutionPolicy.ps1\&quot;&quot;" Execute="deferred" Impersonate="no" Return="check"/>
125+
<CustomAction Id="SetExecutionPolicy" Property="POWERSHELLEXE" ExeCommand="-NoLogo -NoProfile -WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass -Command &quot;. \&quot;[PowerShellFolder]SetExecutionPolicy.ps1\&quot;&quot;" Execute="deferred" Impersonate="no" Return="check"/>
126+
<CustomAction Id="RemoveGalleryModules" Property="POWERSHELLEXE" ExeCommand="-NoLogo -NoProfile -WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass -Command &quot;. \&quot;[PowerShellFolder]RemoveGalleryModules.ps1\&quot;&quot;" Execute="deferred" Impersonate="no" Return="check"/>
137127

138128
<InstallExecuteSequence>
139129
<Custom Action="SetCustomActionDataValue" After="CreateShortcuts">NOT Installed</Custom>
140-
<Custom Action="UpdatePSShortcut" After="SetCustomActionDataValue">NOT Installed</Custom>
130+
<Custom Action="RemoveGalleryModules" After="SetCustomActionDataValue">NOT Installed</Custom>
131+
<Custom Action="UpdatePSShortcut" After="RemoveGalleryModules">NOT Installed</Custom>
141132
<Custom Action="SetExecutionPolicy" After="UpdatePSShortcut">NOT Installed</Custom>
142133
</InstallExecuteSequence>
143134

0 commit comments

Comments
 (0)