This cmdlet allows you to change the published Fully Qualified Domain Name (FQDN) that clients use to connect to a Server 2012 or Server 2012 R2 Remote Desktop Services deployment.  This FQDN is included in .rdp files published via RD Web Access and the RemoteApp and Desktop Connections feed.

A common scenario where the ability to change the published name is useful is when your internal domain is .local, .private, .internal, etc.  For instance, you purchase and install a wildcard certificate (*.yourdomain.com) for use with RDS, but when your users connect they receive a name mismatch error because they are attempting to connect to rdcb.yourdomain.local.  This cmdlet allows you to change the FQDN they will use to a name that will match your certificate (rdcb.yourdomain.com).

 

Syntax

Set-RDPublishedName [-ClientAccessName] <String> [[-ConnectionBroker] <String> ]

Example

In this example the cmdlet is run directly on the RD Connection Broker and we would like to change the published name to remote.contoso.com. We are making this change in order to match our installed wildcard certificate which has a subject of *.contoso.com:

Set-RDPublishedName "remote.contoso.com"

 

To create the cmdlet (You can run this file by double clicking on it). It will prompt you for the FQDN (use external name)


Create file in notepad: "Set-RDPublishName.ps1"


[CmdletBinding()]
Param(
  [Parameter(Mandatory=$True,HelpMessage="Specifies the FQDN that clients will use when connecting to the deployment.",Position=1)]
   [string]$ClientAccessName, 
   [Parameter(Mandatory=$False,HelpMessage="Specifies the RD Connection Broker server for the deployment.",Position=2)]
   [string]$ConnectionBroker="localhost"
)

$Host.UI.RawUI.BackgroundColor = "Black"; Clear-Host

$CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
If (($CurrentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) -eq $false) 
{
    $ArgumentList = "-noprofile -noexit -file `"{0}`" -ClientAccessName $ClientAccessName -ConnectionBroker $ConnectionBroker"
    Start-Process powershell.exe -Verb RunAs -ArgumentList ($ArgumentList -f ($MyInvocation.MyCommand.Definition))
    Exit
}

Function Get-RDMSDeployStringProperty ([string]$PropertyName, [string]$BrokerName)
{
    $ret = iwmi -Class "Win32_RDMSDeploymentSettings" -Namespace "root\CIMV2\rdms" -Name "GetStringProperty" `
        -ArgumentList @($PropertyName) -ComputerName $BrokerName `
        -Authentication PacketPrivacy -ErrorAction Stop
    Return $ret.Value
}

Try
{
    If ((Get-RDMSDeployStringProperty "DatabaseConnectionString" $ConnectionBroker) -eq $null) {$BrokerInHAMode = $False} Else {$BrokerInHAMode = $True}
}
Catch [System.Management.ManagementException]
{
    If ($Error[0].Exception.ErrorCode -eq "InvalidNamespace")
    {
        If ($ConnectionBroker -eq "localhost")
        {
            Write-Host "`n Set-RDPublishedName Failed.`n`n The local machine does not appear to be a Connection Broker.  Please specify the`n FQDN of the RD Connection Broker using the -ConnectionBroker parameter.`n" -ForegroundColor Red
        }
        Else
        {
            Write-Host "`n Set-RDPublishedName Failed.`n`n $ConnectionBroker does not appear to be a Connection Broker.  Please make sure you have `n specified the correct FQDN for your RD Connection Broker server.`n" -ForegroundColor Red
        }
    }
    Else
    {
        $Error[0]
    }
    Exit
}

$OldClientAccessName = Get-RDMSDeployStringProperty "DeploymentRedirectorServer" $ConnectionBroker

If ($BrokerInHAMode.Value)
{
    Import-Module RemoteDesktop
    Set-RDClientAccessName -ConnectionBroker $ConnectionBroker -ClientAccessName $ClientAccessName
}
Else
{
    $return = iwmi -Class "Win32_RDMSDeploymentSettings" -Namespace "root\CIMV2\rdms" -Name "SetStringProperty" `
        -ArgumentList @("DeploymentRedirectorServer",$ClientAccessName) -ComputerName $ConnectionBroker `
        -Authentication PacketPrivacy -ErrorAction Stop
}

$CurrentClientAccessName = Get-RDMSDeployStringProperty "DeploymentRedirectorServer" $ConnectionBroker

If ($CurrentClientAccessName -eq $ClientAccessName)
{
    Write-Host "`n Set-RDPublishedName Succeeded." -ForegroundColor Green
    Write-Host "`n     Old name:  $OldClientAccessName`n`n     New name:  $CurrentClientAccessName"
    Write-Host "`n If you are currently logged on to RD Web Access, please refresh the page for the change to take effect.`n"
}
Else
{
    Write-Host "`n Set-RDPublishedName Failed.`n" -ForegroundColor Red

Article ID: 100, Created On: 3/17/2014, Modified: 3/17/2014

Feedback (0)