4

I have installed Sitecore 9.1.0 XP and Experience Commerce 9.1.0. Now I am trying to uninstall Sitecore Experience Commerce.

Is there any script to achieve this ? or uninstalling XP also uninstalls Sitecore Experience Commerce?

Thanks in advance for any support.

6

Please Use the below script to uninstall sitecore commerce. Replace the parameters that match with your instance parameters.

#define parameters
Param(
    [string]$Prefix = 'SiteInstanceName',   
    [string]$CommerceOpsSiteName = 'CommerceOps_Sc910',
    [string]$CommerceShopsSiteName = 'CommerceShops_Sc910',
    [string]$CommerceAuthoringSiteName = 'CommerceAuthoring_Sc910',
    [string]$CommerceMinionsSiteName = 'CommerceMinions_Sc910',
    [string]$SitecoreBizFxSiteName = 'SitecoreBizFx',
    [string]$SitecoreIdentityServerSiteName = 'SitecoreIdentityServer',
    [string]$SolrService = 'Solr-7.2.1',
    [string]$PathToSolr = 'C:\Solr\Solr-7.2.1',
    [string]$SqlServer = 'DESKTOP\SQLEXPRESS',
    [string]$SqlAccount = 'sa',
    [string]$SqlPassword = 'sa5'
)
#Write-TaskHeader function modified from SIF
Function Write-TaskHeader {
    param(
        [Parameter(Mandatory=$true)]
        [string]$TaskName,
        [Parameter(Mandatory=$true)]
        [string]$TaskType
    )

    function StringFormat {
        param(
            [int]$length,
            [string]$value,
            [string]$prefix = '',
            [string]$postfix = '',
            [switch]$padright
        )

        # wraps string in spaces so we reduce length by two
        $length = $length - 2 #- $postfix.Length - $prefix.Length
        if($value.Length -gt $length){
            # Reduce to length - 4 for elipsis
            $value = $value.Substring(0, $length - 4) + '...'
        }

        $value = " $value "
        if($padright){
            $value = $value.PadRight($length, '*')
        } else {
            $value = $value.PadLeft($length, '*')
        }

        return $prefix + $value + $postfix
    }

    $actualWidth = (Get-Host).UI.RawUI.BufferSize.Width
    $width = $actualWidth - ($actualWidth % 2)
    $half = $width / 2

    $leftString = StringFormat -length $half -value $TaskName -prefix '[' -postfix ':'
    $rightString = StringFormat -length $half -value $TaskType -postfix ']' -padright

    $message = ($leftString + $rightString)
    Write-Host ''
    Write-Host $message -ForegroundColor 'Red'
}

Function Remove-Service{
    [CmdletBinding()]
    param(
        [string]$serviceName
    )
    if(Get-Service "My Service" -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 Solr Service
Write-TaskHeader -TaskName "Solr Services" -TaskType "Stop"
Write-Host "Stopping solr service"
Stop-Service $SolrService -Force -ErrorAction stop
Write-Host "Solr service stopped successfully"

#Delete solr cores
Write-TaskHeader -TaskName "Solr Services" -TaskType "Delete Cores"
Write-Host "Deleting Solr Cores"
$pathToCores = "$pathToSolr\server\solr\$Prefix*"
Remove-Item $pathToCores -recurse -force -ErrorAction stop
Write-Host "Solr Cores deleted successfully"

#Remove Sites and App Pools from IIS
Write-TaskHeader -TaskName "Internet Information Services" -TaskType "Remove Websites"


Write-Host "Deleting Website $CommerceOpsSiteName"
Remove-Website -siteName $CommerceOpsSiteName -ErrorAction stop
Write-Host "Websites deleted"

Write-Host "Deleting Website $CommerceShopsSiteName"
Remove-Website -siteName $CommerceShopsSiteName -ErrorAction stop
Write-Host "Websites deleted"

Write-Host "Deleting Website $CommerceAuthoringSiteName"
Remove-Website -siteName $CommerceAuthoringSiteName -ErrorAction stop
Write-Host "Websites deleted"

Write-Host "Deleting Website $CommerceMinionsSiteName "
Remove-Website -siteName $CommerceMinionsSiteName  -ErrorAction stop
Write-Host "Websites deleted"

Write-Host "Deleting Website $SitecoreBizFxSiteName"
Remove-Website -siteName $SitecoreBizFxSiteName -ErrorAction stop
Write-Host "Websites deleted"

Write-Host "Deleting Website $SitecoreIdentityServerSiteName"
Remove-Website -siteName $SitecoreIdentityServerSiteName -ErrorAction stop
Write-Host "Websites deleted"



Remove-AppPool -appPoolName $CommerceOpsSiteName -ErrorAction stop
Write-Host "Application pools deleted"
Remove-AppPool -appPoolName $CommerceShopsSiteName -ErrorAction stop
Write-Host "Application pools deleted"
Remove-AppPool -appPoolName $CommerceAuthoringSiteName -ErrorAction stop
Write-Host "Application pools deleted"
Remove-AppPool -appPoolName $CommerceMinionsSiteName -ErrorAction stop
Write-Host "Application pools deleted"
Remove-AppPool -appPoolName $SitecoreBizFxSiteName -ErrorAction stop
Write-Host "Application pools deleted"
Remove-AppPool -appPoolName $SitecoreIdentityServerSiteName -ErrorAction stop


Remove-Item C:\inetpub\wwwroot\$CommerceOpsSiteName -recurse -force -ErrorAction stop
Write-Host "Websites removed from wwwroot"
Remove-Item C:\inetpub\wwwroot\$CommerceShopsSiteName -recurse -force -ErrorAction stop
Write-Host "Websites removed from wwwroot"
Remove-Item C:\inetpub\wwwroot\$CommerceAuthoringSiteName -recurse -force -ErrorAction stop
Write-Host "Websites removed from wwwroot"
Remove-Item C:\inetpub\wwwroot\$CommerceMinionsSiteName -recurse -force -ErrorAction stop
Write-Host "Websites removed from wwwroot"
Remove-Item C:\inetpub\wwwroot\$SitecoreBizFxSiteName -recurse -force -ErrorAction stop
Write-Host "Websites removed from wwwroot"
Remove-Item C:\inetpub\wwwroot\$SitecoreIdentityServerSiteName -recurse -force -ErrorAction stop
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 database SitecoreCommerce9_Global")
$commerceDbPrefix = $("DROP DATABASE IF EXISTS [SitecoreCommerce9_Global]")
Write-Host $("Query: $($commerceDbPrefix)")
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $commerceDbPrefix -ErrorAction stop

Write-Host $("Dropping database [SitecoreCommerce9_SharedEnvironments]")
$sharedDbPrefix = $("DROP DATABASE IF EXISTS [SitecoreCommerce9_SharedEnvironments]")
Write-Host $("Query: $($sharedDbPrefix)")
invoke-sqlcmd -ServerInstance $SqlServer -U $SqlAccount -P $SqlPassword -Query $sharedDbPrefix -ErrorAction stop


Write-Host "Databases dropped successfully"
pop-location
0

Additionally, if you need to blow away both XP and XC and start fresh, please check out the batch file linked to at the bottom of my blog post. Contents of the batch file below:

REM *****************************************************
REM This assumes the default and/or recommended names and directories for the Services, Sites, AppPools, etc. Your mileage may vary.
REM 
REM After running this script, it is recommended you manually (and carefully) delete any certificates issued by DO_NOT_TRUST_SitecoreRootCert in the following stores:
REM     Current User\Trusted Root Certification Authorities\Certificates
REM     Local Computer\Personal\Certificates
REM     Local Computer\Trusted Root Certification Authorities\Certificates
REM
REM *****************************************************


@ECHO OFF

sc stop XP0.xconnect-MarketingAutomationService
sc stop XP0.xconnect-ProcessingEngineService
sc stop XP0.xconnect-IndexWorker
sc stop Solr-7.2.1

IISRESET /STOP

sc delete XP0.xconnect-MarketingAutomationService
sc delete XP0.xconnect-ProcessingEngineService
sc delete XP0.xconnect-IndexWorker

C:\Windows\System32\inetsrv\appcmd.exe delete site XP0.identityserver
C:\Windows\System32\inetsrv\appcmd.exe delete site XP0.xconnect
C:\Windows\System32\inetsrv\appcmd.exe delete site XP0.sc
C:\Windows\System32\inetsrv\appcmd.exe delete site CommerceAuthoring_Sc9
C:\Windows\System32\inetsrv\appcmd.exe delete site CommerceMinions_Sc9
C:\Windows\System32\inetsrv\appcmd.exe delete site CommerceOps_Sc9
C:\Windows\System32\inetsrv\appcmd.exe delete site CommerceShops_Sc9
C:\Windows\System32\inetsrv\appcmd.exe delete site SitecoreBizFx

C:\Windows\System32\inetsrv\appcmd.exe delete apppool XP0.identityserver
C:\Windows\System32\inetsrv\appcmd.exe delete apppool XP0.xconnect
C:\Windows\System32\inetsrv\appcmd.exe delete apppool XP0.sc
C:\Windows\System32\inetsrv\appcmd.exe delete apppool CommerceAuthoring_Sc9
C:\Windows\System32\inetsrv\appcmd.exe delete apppool CommerceMinions_Sc9
C:\Windows\System32\inetsrv\appcmd.exe delete apppool CommerceOps_Sc9
C:\Windows\System32\inetsrv\appcmd.exe delete apppool CommerceShops_Sc9
C:\Windows\System32\inetsrv\appcmd.exe delete apppool SitecoreBizFx

RD C:\inetpub\wwwroot\XP0.identityserver /S /Q
RD C:\inetpub\wwwroot\XP0.xconnect /S /Q
RD C:\inetpub\wwwroot\XP0.sc /S /Q
RD C:\inetpub\wwwroot\CommerceAuthoring_Sc9 /S /Q
RD C:\inetpub\wwwroot\CommerceMinions_Sc9 /S /Q
RD C:\inetpub\wwwroot\CommerceOps_Sc9 /S /Q
RD C:\inetpub\wwwroot\CommerceShops_Sc9 /S /Q
RD C:\inetpub\wwwroot\SitecoreBizFx /S /Q

sqlcmd -Q "drop database [XP0_MarketingAutomation]"
sqlcmd -Q "drop database [XP0_Messaging]"
sqlcmd -Q "drop database [XP0_Processing.Pools]"
sqlcmd -Q "drop database [XP0_ProcessingEngineStorage]"
sqlcmd -Q "drop database [XP0_ProcessingEngineTasks]"
sqlcmd -Q "drop database [XP0_ReferenceData]"
sqlcmd -Q "drop database [XP0_Reporting]"
sqlcmd -Q "drop database [XP0_Xdb.Collection.Shard0]"
sqlcmd -Q "drop database [XP0_Xdb.Collection.Shard1]"
sqlcmd -Q "drop database [XP0_Xdb.Collection.ShardMapManager]"
sqlcmd -Q "drop database [XP0_Core]"
sqlcmd -Q "drop database [XP0_Master]"
sqlcmd -Q "drop database [XP0_Web]"
sqlcmd -Q "drop database [SitecoreCommerce9_Global]"
sqlcmd -Q "drop database [SitecoreCommerce9_SharedEnvironments]"
sqlcmd -Q "drop database [XP0_EXM.Master]"
sqlcmd -Q "drop database [XP0_ExperienceForms]"
sqlcmd -Q "drop database [XP0_Processing.Tasks]"

sqlcmd -Q "drop login [XP0_collectionuser]"
sqlcmd -Q "drop login [%COMPUTERNAME%\CSFndRuntimeUser]"

net user CSFndRuntimeUser /DELETE

net stop MSSQLSERVER

FOR /d %%i in (C:\solr-7.2.1\server\solr\XP0*.*) DO RD "%%i" /S /Q
FOR /d %%i in (C:\solr-7.2.1\server\solr\Sitecore*.*) DO RD "%%i" /S /Q 

DEL C:\Certificates\*.* /Q
DEL C:\Encryption-Keys\*.* /Q

sc start Solr-7.2.1
net start MSSQLSERVER
iisreset /start

The only thing it won't clean out automatically are the DO_NOT_TRUST certificates created through the XC installation.

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.