Tag Archives: Database

Updating Database Connection Strings in XenDesktop 7.x

The scripts need powershell v3 at the moment (I may turn part of it into a module, and might be able to switch to powershell v2, but v3 is needed to load the core script into the other scripts.)

The scripts have been tested on Server 2012 R2, with XenDesktop 7.5 and XenDesktop 7.6. Note that this was as a full site admin and in local admin powershell window.

The provided scripts are:
DBConnectionStringFuncs.ps1 – this is the core script, and does the actual work. It contains common functions which the following scripts then use.
Change_XD_Failover_Partner_v1.ps1 – this is similar to the previous script I posted, and is used to update the failover partner.
Change_XD_To_ConnectionString.ps1 – this takes passed in connection strings and uses them, so a very generic version.
Change_XD_To_MultiSubnetFailover.ps1 – this toggles the addition and removal of MultiSubnetFailover=true. IE run it once and the option is added, run it again and the options is removed.
Change_XD_To_Null.ps1 – this is a reset of all the connection strings on the localhost as something has gone wrong. Note because this resets the connection strings to null, it will actually place the ddc into a “initial” state. IE if you run studio it’ll ask if you want to create a site, or join to another ddc. This is useful is something has gone wrong somewhere, and a reset is needed, as you can then attempt to set the connection strings again.

If you need to do some kind of connection string manipulation feel free to look at how the Change_XD scripts use the functions in DBConnectionStringFuncs.ps1.
XDConnectionStringScripts

Script used for enable XenDesktop Database Mirroring

Make sure that all DDCs are up and running, then run below PowerShell Script.

$cs = 'Data Source=DB1; Failover Partner=DB2; Initial Catalog=XenDesktopDB; Integrated Security=True; Network=dbmssocn’


$controllers = Get-BrokerController | %{$_.DNSName}
foreach ($controller in $controllers) {
    Write-Host "Disconnect controller $controller ..."
    Set-ConfigDBConnection –DBConnection $null –AdminAddress $controller
    Set-HypDBConnection –DBConnection $null –AdminAddress $controller
    Set-AcctDBConnection –DBConnection $null –AdminAddress $controller
    Set-ProvDBConnection –DBConnection $null –AdminAddress $controller
    Set-PvsVmDBConnection –DBConnection $null –AdminAddress $controller
    Set-BrokerDBConnection –DBConnection $null –AdminAddress $controller
} 



    Set-ConfigDBConnection –DBConnection $cs –AdminAddress $controller
    Set-HypDBConnection –DBConnection $cs –AdminAddress $controller
    Set-AcctDBConnection –DBConnection $cs –AdminAddress  $controller
    Set-ProvDBConnection –DBConnection $cs –AdminAddress $controller
    Set-PvsVmDBConnection –DBConnection $cs –AdminAddress $controller
    Set-BrokerDBConnection –DBConnection $cs –AdminAddress $controller