Sitecore and Sitecore Commerce 9.2 Instance Uninstall PS Script
Based on https://naveed-ahmad.com/2018/02/23/sitecore-experience-commerce-xc9-the-uninstall-script/ but, uninstalls Vanilla Sitecore instance too apart from Commerce instance.
Copy over the below script and save to name you wish with ps1 extension. Run from Powershell. Just modify params based on what is passed in install script. This uninstalls both Vanilla Sitecore and Commerce Instance including websites, app pools, solr core folders, DBs and windows services. It doesn't delete folders from the following locations:
c:\users
c:\certificates
Copy from below this line (replace param values based on install script):
#define parameters
Param(
[string]$Prefix = "sc92commdev3",
[string]$SiteName = "sc92commdev3.local",
[string]$SitecoreBizFxSiteName = "SitecoreBizFx-dev3",
[string]$CommerceServicesPostfix = "Sc9dev3",
[string]$SolrService = 'Solr-7.5.0',
[string]$PathToSolr = 'C:\Solr\Solr-7.5.0',
[string]$SqlServer = 'mysqlservername',
[string]$SqlAccount = 'sa',
[string]$SqlPassword = 'mysqlpwd',
[string]$CommerceServicesHostPostfix = "$CommerceServicesPostfix.com",
[string]$CommerceOpsSiteName = "CommerceOps_$CommerceServicesPostfix",
[string]$CommerceShopsSiteName = "CommerceShops_$CommerceServicesPostfix",
[string]$CommerceAuthoringSiteName = "CommerceAuthoring_$CommerceServicesPostfix",
[string]$CommerceMinionsSiteName = "CommerceMinions_$CommerceServicesPostfix",
[string]$SitecoreIdentityServerSiteName = "$SiteName.Identityserver",
[string]$SitecorexConnectSiteName = "$SiteName.xconnect",
[string]$SitecoreMarketingAutomationService="$SitecorexConnectSiteName-MarketingAutomationService",
[string]$SitecoreProcessingEngineService="$SitecorexConnectSiteName-ProcessingEngineService",
[string]$SitecoreIndexWorkerService="$SitecorexConnectSiteName-IndexWorker"
)
Function Remove-Service{
[CmdletBinding()]
param(
[string]$serviceName
)
if(Get-Service $serviceName -ErrorAction SilentlyContinue){
sc.exe delete $serviceName
}
}
Function Remove-Website{
[CmdletBinding()]
param(
[string]$siteName
)
$appCmd = "C:\windows\system32\inetsrv\appcmd.exe"
& $appCmd delete site $siteName
}
Function Remove-AppPool{
[CmdletBinding()]
param(
[string]$appPoolName
)
$appCmd = "C:\windows\system32\inetsrv\appcmd.exe"
& $appCmd delete apppool $appPoolName
}
Stop-Website -Name $CommerceOpsSiteName
Stop-Website -Name $CommerceShopsSiteName
Stop-Website -Name $CommerceAuthoringSiteName
Stop-Website -Name $CommerceMinionsSiteName
Stop-Website -Name $SitecoreBizFxSiteName
Stop-Website -Name $SitecoreIdentityServerSiteName
Stop-Website -Name $SiteName
Stop-Website -Name $SitecorexConnectSiteName
Stop-WebAppPool -Name $CommerceOpsSiteName
Stop-WebAppPool -Name $CommerceShopsSiteName
Stop-WebAppPool -Name $CommerceAuthoringSiteName
Stop-WebAppPool -Name $CommerceMinionsSiteName
Stop-WebAppPool -Name $SitecoreBizFxSiteName
Stop-WebAppPool -Name $SitecoreIdentityServerSiteName
Stop-WebAppPool -Name $SiteName
Stop-WebAppPool -Name $SitecorexConnectSiteName
#Stop Solr Service
Write-Host "Stopping solr service"
Stop-Service $SolrService -Force -ErrorAction stop
Write-Host "Solr service stopped successfully"
#Delete solr cores
Write-Host "Deleting Solr Cores"
$pathToCores = "$pathToSolr\server\solr\$Prefix*"
Remove-Item $pathToCores -recurse -force -ErrorAction stop
Write-Host "Solr Cores deleted successfully"
Write-Host "Stopping Marketing Automation service"
Stop-Service $SitecoreMarketingAutomationService -Force -ErrorAction stop
Write-Host "Marketing Automation service stopped successfully"
Remove-Service $SitecoreMarketingAutomationService
Write-Host "Stopping Processing Engine service"
Stop-Service $SitecoreProcessingEngineService -Force -ErrorAction stop
Write-Host "Processing Engine service stopped successfully"
Remove-Service $SitecoreProcessingEngineService
Write-Host "Stopping Index Worker service"
Stop-Service $SitecoreIndexWorkerService -Force -ErrorAction stop
Write-Host "Index Worker service stopped successfully"
Remove-Service $SitecoreIndexWorkerService
#Remove Sites and App Pools from IIS
Write-Host "Deleting Websites"
Remove-Website -siteName $CommerceOpsSiteName -ErrorAction stop
Remove-Website -siteName $CommerceShopsSiteName -ErrorAction stop
Remove-Website -siteName $CommerceAuthoringSiteName -ErrorAction stop
Remove-Website -siteName $CommerceMinionsSiteName -ErrorAction stop
Remove-Website -siteName $SitecoreBizFxSiteName -ErrorAction stop
Remove-Website -siteName $SitecorexConnectSiteName -ErrorAction stop
Remove-Website -siteName $SitecoreIdentityServerSiteName -ErrorAction stop
Remove-Website -siteName $SiteName -ErrorAction stop
Write-Host "Websites deleted"
Write-Host "Deleting Application pools"
Remove-AppPool -appPoolName $CommerceOpsSiteName -ErrorAction stop
Remove-AppPool -appPoolName $CommerceShopsSiteName -ErrorAction stop
Remove-AppPool -appPoolName $CommerceAuthoringSiteName -ErrorAction stop
Remove-AppPool -appPoolName $CommerceMinionsSiteName -ErrorAction stop
Remove-AppPool -appPoolName $SitecoreBizFxSiteName -ErrorAction stop
Remove-AppPool -appPoolName $SitecoreIdentityServerSiteName -ErrorAction stop
Remove-AppPool -appPoolName $SiteName -ErrorAction stop
Remove-AppPool -appPoolName $SitecorexConnectSiteName -ErrorAction stop
Write-Host "Application pools deleted"
Write-Host "Deleting Websites from wwwroot"
rm C:\inetpub\wwwroot\$CommerceOpsSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$CommerceShopsSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$CommerceAuthoringSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$CommerceMinionsSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$SitecoreBizFxSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$SitecoreIdentityServerSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$SiteName -recurse -force -ea ig
rm C:\inetpub\wwwroot\$SitecorexConnectSiteName -recurse -force -ea ig
Write-Host "Websites removed from wwwroot"
#Write-TaskHeader -TaskName "SQL Server" -TaskType "Drop Databases"
#Drop databases from SQL
Write-Host "Dropping databases from SQL server"
push-location
import-module sqlps
Write-Host $("Dropping Sitecore databases")
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Core]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Master]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Web]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_EXM.Master]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_ReferenceData]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Reporting]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_ExperienceForms]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_MarketingAutomation]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Processing.Pools]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Processing.Tasks]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_ProcessingEngineStorage]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_ProcessingEngineTasks]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Xdb.Collection.Shard0]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Xdb.Collection.Shard1]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Xdb.Collection.ShardMapManager]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Messaging]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$commerceDbPrefix = "DROP DATABASE IF EXISTS [" + $Prefix + "_Global]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $commerceDbPrefix -ErrorAction stop
$commerceDbPrefix = "DROP DATABASE IF EXISTS [" + $Prefix + "_SharedEnvironments]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $commerceDbPrefix -ErrorAction stop
Write-Host "Databases dropped successfully"
pop-location
Copy over the below script and save to name you wish with ps1 extension. Run from Powershell. Just modify params based on what is passed in install script. This uninstalls both Vanilla Sitecore and Commerce Instance including websites, app pools, solr core folders, DBs and windows services. It doesn't delete folders from the following locations:
c:\users
c:\certificates
Copy from below this line (replace param values based on install script):
#define parameters
Param(
[string]$Prefix = "sc92commdev3",
[string]$SiteName = "sc92commdev3.local",
[string]$SitecoreBizFxSiteName = "SitecoreBizFx-dev3",
[string]$CommerceServicesPostfix = "Sc9dev3",
[string]$SolrService = 'Solr-7.5.0',
[string]$PathToSolr = 'C:\Solr\Solr-7.5.0',
[string]$SqlServer = 'mysqlservername',
[string]$SqlAccount = 'sa',
[string]$SqlPassword = 'mysqlpwd',
[string]$CommerceServicesHostPostfix = "$CommerceServicesPostfix.com",
[string]$CommerceOpsSiteName = "CommerceOps_$CommerceServicesPostfix",
[string]$CommerceShopsSiteName = "CommerceShops_$CommerceServicesPostfix",
[string]$CommerceAuthoringSiteName = "CommerceAuthoring_$CommerceServicesPostfix",
[string]$CommerceMinionsSiteName = "CommerceMinions_$CommerceServicesPostfix",
[string]$SitecoreIdentityServerSiteName = "$SiteName.Identityserver",
[string]$SitecorexConnectSiteName = "$SiteName.xconnect",
[string]$SitecoreMarketingAutomationService="$SitecorexConnectSiteName-MarketingAutomationService",
[string]$SitecoreProcessingEngineService="$SitecorexConnectSiteName-ProcessingEngineService",
[string]$SitecoreIndexWorkerService="$SitecorexConnectSiteName-IndexWorker"
)
Function Remove-Service{
[CmdletBinding()]
param(
[string]$serviceName
)
if(Get-Service $serviceName -ErrorAction SilentlyContinue){
sc.exe delete $serviceName
}
}
Function Remove-Website{
[CmdletBinding()]
param(
[string]$siteName
)
$appCmd = "C:\windows\system32\inetsrv\appcmd.exe"
& $appCmd delete site $siteName
}
Function Remove-AppPool{
[CmdletBinding()]
param(
[string]$appPoolName
)
$appCmd = "C:\windows\system32\inetsrv\appcmd.exe"
& $appCmd delete apppool $appPoolName
}
Stop-Website -Name $CommerceOpsSiteName
Stop-Website -Name $CommerceShopsSiteName
Stop-Website -Name $CommerceAuthoringSiteName
Stop-Website -Name $CommerceMinionsSiteName
Stop-Website -Name $SitecoreBizFxSiteName
Stop-Website -Name $SitecoreIdentityServerSiteName
Stop-Website -Name $SiteName
Stop-Website -Name $SitecorexConnectSiteName
Stop-WebAppPool -Name $CommerceOpsSiteName
Stop-WebAppPool -Name $CommerceShopsSiteName
Stop-WebAppPool -Name $CommerceAuthoringSiteName
Stop-WebAppPool -Name $CommerceMinionsSiteName
Stop-WebAppPool -Name $SitecoreBizFxSiteName
Stop-WebAppPool -Name $SitecoreIdentityServerSiteName
Stop-WebAppPool -Name $SiteName
Stop-WebAppPool -Name $SitecorexConnectSiteName
#Stop Solr Service
Write-Host "Stopping solr service"
Stop-Service $SolrService -Force -ErrorAction stop
Write-Host "Solr service stopped successfully"
#Delete solr cores
Write-Host "Deleting Solr Cores"
$pathToCores = "$pathToSolr\server\solr\$Prefix*"
Remove-Item $pathToCores -recurse -force -ErrorAction stop
Write-Host "Solr Cores deleted successfully"
Write-Host "Stopping Marketing Automation service"
Stop-Service $SitecoreMarketingAutomationService -Force -ErrorAction stop
Write-Host "Marketing Automation service stopped successfully"
Remove-Service $SitecoreMarketingAutomationService
Write-Host "Stopping Processing Engine service"
Stop-Service $SitecoreProcessingEngineService -Force -ErrorAction stop
Write-Host "Processing Engine service stopped successfully"
Remove-Service $SitecoreProcessingEngineService
Write-Host "Stopping Index Worker service"
Stop-Service $SitecoreIndexWorkerService -Force -ErrorAction stop
Write-Host "Index Worker service stopped successfully"
Remove-Service $SitecoreIndexWorkerService
#Remove Sites and App Pools from IIS
Write-Host "Deleting Websites"
Remove-Website -siteName $CommerceOpsSiteName -ErrorAction stop
Remove-Website -siteName $CommerceShopsSiteName -ErrorAction stop
Remove-Website -siteName $CommerceAuthoringSiteName -ErrorAction stop
Remove-Website -siteName $CommerceMinionsSiteName -ErrorAction stop
Remove-Website -siteName $SitecoreBizFxSiteName -ErrorAction stop
Remove-Website -siteName $SitecorexConnectSiteName -ErrorAction stop
Remove-Website -siteName $SitecoreIdentityServerSiteName -ErrorAction stop
Remove-Website -siteName $SiteName -ErrorAction stop
Write-Host "Websites deleted"
Write-Host "Deleting Application pools"
Remove-AppPool -appPoolName $CommerceOpsSiteName -ErrorAction stop
Remove-AppPool -appPoolName $CommerceShopsSiteName -ErrorAction stop
Remove-AppPool -appPoolName $CommerceAuthoringSiteName -ErrorAction stop
Remove-AppPool -appPoolName $CommerceMinionsSiteName -ErrorAction stop
Remove-AppPool -appPoolName $SitecoreBizFxSiteName -ErrorAction stop
Remove-AppPool -appPoolName $SitecoreIdentityServerSiteName -ErrorAction stop
Remove-AppPool -appPoolName $SiteName -ErrorAction stop
Remove-AppPool -appPoolName $SitecorexConnectSiteName -ErrorAction stop
Write-Host "Application pools deleted"
Write-Host "Deleting Websites from wwwroot"
rm C:\inetpub\wwwroot\$CommerceOpsSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$CommerceShopsSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$CommerceAuthoringSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$CommerceMinionsSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$SitecoreBizFxSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$SitecoreIdentityServerSiteName -force -recurse -ea ig
rm C:\inetpub\wwwroot\$SiteName -recurse -force -ea ig
rm C:\inetpub\wwwroot\$SitecorexConnectSiteName -recurse -force -ea ig
Write-Host "Websites removed from wwwroot"
#Write-TaskHeader -TaskName "SQL Server" -TaskType "Drop Databases"
#Drop databases from SQL
Write-Host "Dropping databases from SQL server"
push-location
import-module sqlps
Write-Host $("Dropping Sitecore databases")
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Core]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Master]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Web]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_EXM.Master]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_ReferenceData]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Reporting]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_ExperienceForms]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_MarketingAutomation]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Processing.Pools]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Processing.Tasks]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_ProcessingEngineStorage]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_ProcessingEngineTasks]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Xdb.Collection.Shard0]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Xdb.Collection.Shard1]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Xdb.Collection.ShardMapManager]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$sitecoreDbPrefix = "DROP DATABASE IF EXISTS [" + $SiteName + "_Messaging]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sitecoreDbPrefix -ErrorAction stop
$commerceDbPrefix = "DROP DATABASE IF EXISTS [" + $Prefix + "_Global]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $commerceDbPrefix -ErrorAction stop
$commerceDbPrefix = "DROP DATABASE IF EXISTS [" + $Prefix + "_SharedEnvironments]"
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $commerceDbPrefix -ErrorAction stop
Write-Host "Databases dropped successfully"
pop-location
Comments
Post a Comment