PowerShell: Add RDS Server Role

Step 0: Searching for RDS Licensing Server

# Pick from 1 of these commands:

Get-ADObject -LDAPFilter "(&(CN=TermServLicensing)(objectClass=serviceConnectionPoint))"

Get-ADObject -Filter {objectClass -eq 'serviceConnectionPoint' -and Name -eq 'TermServLicensing'}

dsquery * -filter "(&(CN=TermServLicensing)(objectClass=serviceConnectionPoint))"

Step 1: Adding RDS Role

# To add Remote Desktop Server Role
# Add-WindowsFeature RDS-RD-Server
Install-WindowsFeature RDS-RD-Server -IncludeManagementTools

# Reboot server for changes to take effect
Restart-Computer -force

Step 2: Config RDS with a License Server

# addRdsServerLicense
# To Configure RDS Role

$mode='PerUser'
$licenseServerName='rdsServer.kimconnect.com'

# Set-RDLicenseConfiguration : The term 'Set-RDLicenseConfiguration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
# the name, or if a path was included, verify that the path is correct and try again.
# At line:1 char:1
# + Set-RDLicenseConfiguration -LicenseServer $licenseServerName -Mode $m ...
# + ~~~~~~~~~~~~~~~~~~~~~~~~~~
#     + CategoryInfo          : ObjectNotFound: (Set-RDLicenseConfiguration:String) [], CommandNotFoundException
#     + FullyQualifiedErrorId : CommandNotFoundException
# import-module remoteDesktop
# Set-RDLicenseConfiguration -LicenseServer $licenseServerName -Mode $mode
# restart-computer -Force

# To set licensing mode and/or licensing server
$licensingModes=@{
    'PerDevice'=2
    'PerUser'=4
}
$tsSettings = gwmi -namespace "Root/CIMV2/TerminalServices" Win32_TerminalServiceSetting
$tsSettings.ChangeMode($licensingModes[$mode])
$tsSettings.SetSpecifiedLicenseServerList($licenseServerName)
$tsSettings.GetSpecifiedLicenseServerList()

# Sample output
# PS C:\Windows\system32> $obj.GetSpecifiedLicenseServerList()
# __GENUS          : 2
# __CLASS          : __PARAMETERS
# __SUPERCLASS     :
# __DYNASTY        : __PARAMETERS
# __RELPATH        :
# __PROPERTY_COUNT : 2
# __DERIVATION     : {}
# __SERVER         :
# __NAMESPACE      :
# __PATH           :
# ReturnValue      : 0
# SpecifiedLSList  : {rdsLicense.kimconnect.com}
# PSComputerName   :

# Verify results
lsdiag.msc

Step 3: Optional – Adding RDS Deployments for Advanced Setups

# Error when remote desktop deployment doesn't exist
# Get-RDLicenseConfiguration : A Remote Desktop Services deployment does not exist on rds1.kimconnect.com. This
# operation can be performed after creating a deployment. For information about creating a deployment, run "Get-Help
# New-RDVirtualDesktopDeployment" or "Get-Help New-RDSessionDeployment".
# At line:1 char:1
# + Get-RDLicenseConfiguration
# + ~~~~~~~~~~~~~~~~~~~~~~~~~~
#     + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
#     + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-RDLicenseConfiguration

# Deploy RDS Services
import-module remoteDesktop
$thisServer="$env:computername.$env:USERDNSDOMAIN"
New-SessionDeployment -ConnectionBroker $thisServer -WebAccessServer $thisServer -SessionHost $thisServer

# If additional RD Session Host or RD Licensing
$addServer='rds2.kimconnect.com'
$licenseServerName='rdsLicense.kimconnect.com'
Add-RDServer -Server $addServer -Role RDS-RD-SERVER -ConnectionBroker $thisServer
Set-RDLicenseConfiguration -LicenseServer $licenseServerName -Mode $mode -ConnectionBroker $thisServer

new-rdvirtualdesktopdeployment
new-rdsessioncollection

$connectionBroker=(Get-RDConnectionBrokerHighAvailability -ConnectionBroker).ActiveManagementServer
Get-RDServer -Connectionbroker $connectionBroker

Misc: Other Methods

# Legacy method to configure registry to enable multiple sessions (doesn't work for Windows Server 2016)
$tsRegHive='REGISTRY::HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server'
Set-ItemProperty -Path $tsRegHive -Name fSingleSessionPerUser -value 0
Set-ItemProperty -Path $tsRegHive -Name fdenyTSConnections -value 0
get-itemproperty $tsRegHive

Leave a Reply

Your email address will not be published. Required fields are marked *