This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.ps1
105 lines (93 loc) · 3.31 KB
/
uninstall.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#Requires -RunAsAdministrator
[CmdletBinding()]
param (
[Parameter()]
[string]
$fileName
)
$program32 = "${env:ProgramFiles(x86)}\IIS Express"
$program64 = "${env:ProgramFiles}\IIS Express"
$schema = '\config\schema\httpplatform_schema.xml'
$module = '\httpPlatformHandler.dll'
$sectionName = 'httpPlatform'
$globalModuleName = 'httpPlatformHandler'
function RemoveSchemaFiles {
$schema32 = $program32 + $schema
$schema64 = $program64 + $schema
if (Test-Path $schema32) {
Remove-Item $schema32
Write-Host 'Removed schema 32 bit.'
}
if (Test-Path $schema64) {
Remove-Item $schema64
Write-Host 'Removed schema 64 bit.'
}
}
function RemoveModuleFiles {
$module32 = $program32 + $module
$module64 = $program64 + $module
if (Test-Path $module32) {
Remove-Item $module32
Write-Host 'Removed module 32 bit.'
}
if (Test-Path $module64) {
Remove-Item $module64
Write-Host 'Removed module 64 bit.'
}
}
function UnpatchConfigFile([string]$source) {
if (Test-Path $source) {
[xml]$xmlDoc = Get-Content $source
$existing = $xmlDoc.SelectSingleNode("/configuration/configSections/sectionGroup[@name=`"system.webServer`"]/section[@name=`"$sectionName`"]")
if ($existing) {
$parent = $xmlDoc.SelectSingleNode('/configuration/configSections/sectionGroup[@name="system.webServer"]')
if ($parent) {
$parent.RemoveChild($existing) | Out-Null
$xmlDoc.Save($source)
Write-Host "Removed section $sectionName."
} else {
Write-Host 'Invalid config file.'
}
} else {
Write-Host "Section $sectionName not registered."
}
$global = $xmlDoc.SelectSingleNode("/configuration/system.webServer/globalModules/add[@name=`"$globalModuleName`"]")
if ($global) {
$parent = $xmlDoc.SelectSingleNode('/configuration/system.webServer/globalModules')
if ($parent) {
$parent.RemoveChild($global) | Out-Null
$xmlDoc.Save($source)
Write-Host 'Removed global module.'
} else {
Write-Warning 'Invalid config file.'
}
} else {
Write-Host 'Global module not registered.'
}
$module = $xmlDoc.SelectSingleNode("/configuration/location[@path=`"`"]/system.webServer/modules/add[@name=`"$globalModuleName`"]")
if ($module) {
$parent = $xmlDoc.SelectSingleNode('/configuration/location[@path=""]/system.webServer/modules')
if ($parent) {
$parent.RemoveChild($module) | Out-Null
$xmlDoc.Save($source)
Write-Host 'Removed module.'
} else {
Write-Warning 'Invalid config file.'
}
} else {
Write-Host 'Module not registered.'
}
} else {
Write-Host 'Cannot find config file.'
}
}
if ($fileName) {
Write-Host "Configure $fileName."
UnpatchConfigFile($fileName)
} else {
Write-Host 'Configure all steps and default config file.'
RemoveSchemaFiles
RemoveModuleFiles
UnpatchConfigFile([Environment]::GetFolderPath("MyDocuments") + "\IISExpress\config\applicationHost.config")
}
Write-Host 'All done.'