-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUninstaller-SitecoreXP.ps1
More file actions
111 lines (83 loc) · 3.61 KB
/
Uninstaller-SitecoreXP.ps1
File metadata and controls
111 lines (83 loc) · 3.61 KB
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
106
107
108
109
110
### UNINSTALL SITECORE XP VERSIONS 9.3, 10.x ###
### Script created by Álvaro Montenegro - 2024 ###
### VARIABLES ####
$websiteName = "<website-name>"
$websiteRootPath = "C:\inetpub\wwwroot\<instance-name>"
$hostsFilePath = "C:\Windows\System32\drivers\etc\hosts"
$removeSolr = $false;
$solrServiceName = "Solr-8.8.2"
$solrPath = "C:\Solr\Solr-8.8.2"
$serverName = "<server-name>"
$serverUserName = "<username>"
$serverPassword = "<password>"
#Databases - Has different ones? Just add/remove it from the list below
$databaseNames = @("Core", "EXM.Master", "ExperienceForms", "MarketingAutomation", "Master", "Messaging", "Preview", "Processing.Pools", "Processing.Tasks", "ProcessingEngineStorage", "ProcessingEngineTasks", "ReferenceData", "Reporting", "Web", "Xdb.Collection.Shard0", "Xdb.Collection.Shard1", "Xdb.Collection.ShardMapManager")
#############################################################
[System.Environment]::NewLine
Write-Host "Starting the Sitecore Uninstall..."
[System.Environment]::NewLine
$scServer = $websiteName + "sc.dev.local"
$identifyServer = $websiteName + "identityserver.dev.local"
$xConnectServer = $websiteName + "xconnect.dev.local"
# Step 1: Remove the IIS configuration
if(Test-Path IIS:\Sites\$scServer) {
Remove-Website -Name $scServer
}
if(Test-Path IIS:\Sites\$identifyServer) {
Remove-Website -Name $identifyServer
}
if(Test-Path IIS:\Sites\$xConnectServer) {
Remove-Website -Name $xConnectServer
}
Write-Host "1. Sites completely removed."
if(Test-Path IIS:\AppPools\$scServer) {
Remove-WebAppPool -Name $scServer
}
if(Test-Path IIS:\AppPools\$identifyServer) {
Remove-WebAppPool -Name $identifyServer
}
if(Test-Path IIS:\AppPools\$xConnectServer) {
Remove-WebAppPool -Name $xConnectServer
}
Write-Host "2. AppPools completely removed."
# Step 2: Delete entries in the hosts file
$filecontent = Get-Content -Path $hostsFilePath
$changedfilecontent = $filecontent -replace "\d.*$($scServer)*", ""
$changedfilecontent = $changedfilecontent -replace "\d.*$($identifyServer)*", ""
$changedfilecontent = $changedfilecontent -replace "\d.*$($xConnectServer)*", ""
$changedfilecontent | Out-File $hostsFilePath
Write-Host "3. Entry Hosts completely removed."
# Step 3: Delete associated Windows services
$services = @("-MarketingAutomationService", "-ProcessingEngineService", "-IndexWorker")
$services | ForEach-Object {
$service = Get-Service -Name $xConnectServer$_ -ErrorAction SilentlyContinue
if ($service.Length -gt 0) {
Stop-Service -Name $xConnectServer$_ -Force
sc.exe delete $xConnectServer$_
}
}
Write-Host "4. Windows Services completely removed."
# Step 4: Delete the databases from the Sitecore solution
foreach ($databaseName in $databaseNames) {
$database = $websiteName+"_"+$databaseName
$query = "Drop database [$database]"
if(($db = Get-SqlDatabase -ServerInstance $serverName -Name $database -ErrorAction SilentlyContinue)) {
Write-Host "- Removing: $database"
invoke-sqlcmd -ServerInstance $serverName -U $serverUserName -P $serverPassword -Query $query
}
}
Write-Host "5. Databases completely removed."
# Step 5: Delete the file directory
if(Test-Path IIS:\Sites\$websiteRootPath) {
Remove-Item -Path $websiteRootPath -Recurse -Force
}
Write-Host "6. Root folder completely removed."
# Step 6: Delete/Remove Solr service
if($removeSolr) {
Stop-Service -Name $solrServiceName -Force
sc.exe delete $solrServiceName
Remove-Item -Path $solrPath -Recurse -Force
Write-Host "7. Solr completely removed."
}
[System.Environment]::NewLine
Write-Host "Sitecore instance uninstallation completed successfully!"