How to configure XenDesktop to use Mirror database
If you use SQL Mirror during the deployment of XenDesktop, we recommend that users initialize the XenDesktop site configuration after configuring Mirror, so that mirror database connections are included by default in Connection string. But sometimes it is inevitable that users will configure the site first and then configure the mirror, which will make things very complicated. It takes dozens of commands to reset the connection string of all service, and the slightest carelessness may cause the environment to hang up. Here I have sorted out 2 simple scripts for your use.
Matters needing attention
Be sure to take snapshots of DDC and DB before modification. This script is only applicable to 7.15 LTSR. The number of services varies with different versions. Please modify it yourself.
Concrete steps
We first need to empty the connection string in DDC. You can save the following content as a ps1 file to DDC and execute it with administrator privileges.
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ DesktopServer\ DataStore\ Connections\ Controller ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ ADIdentitySchema\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ Analytics\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ AppLibrarySchema\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ ConfigLoggingSiteSchema\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ ConfigurationSchema\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ DAS\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ DesktopUpdateManagerSchema\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ EnvTestServiceSchema\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ HostingUnitServiceSchema\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ Monitor\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ OrchestrationSchema\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ StorefrontSchema\ DataStore\ Connections ConnectionString $null
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ TrustSchema\ DataStore\ Connections ConnectionString $null
Reset connection string on restart DDCDDC. Change the server address by yourself. Save the ps1 file DDC and execute it through Powershell.
Asnp citrix*
$cs= "Server=DB.ctx.com;Failover Partner=DB2.ctx.com;Initial Catalog=Citrixsite;Integrated Security=True"
$cslog= "Server=DB.ctx.com;Failover Partner=DB2.ctx.com;Initial Catalog=CitrixLogging;Integrated Security=True"
$csmonitor= "Server=DB.ctx.com;Failover Partner=DB2.ctx.com;Initial Catalog=CitrixMonitoring;Integrated Security=True"
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ DesktopServer\ DataStore\ Connections\ Controller ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ ADIdentitySchema\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ Analytics\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ AppLibrarySchema\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ ConfigLoggingSiteSchema\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ ConfigurationSchema\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ DAS\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ DesktopUpdateManagerSchema\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ EnvTestServiceSchema\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ HostingUnitServiceSchema\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ Monitor\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ OrchestrationSchema\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ StorefrontSchema\ DataStore\ Connections ConnectionString $cs
Set-ItemProperty-Path HKLM:\ SOFTWARE\ Citrix\ XDservices\ TrustSchema\ DataStore\ Connections ConnectionString $cs
Set-MonitorDBConnection-datastore Monitor-DBConnection $null
Set-MonitorDBConnection-datastore Monitor-DBConnection $csmonitor
Set-LogDBConnection-datastore Logging-DBConnection $null
Set-LogDBConnection-datastore Logging-DBConnection $cslog
Restart DDC. If you have more than one DDC, you need to modify it separately.
I hope it will be helpful to all of you.