Step 0: Searching for RDS Licensing Server
# Get TS Licensing Servers
$termLicenseServers=Get-ADGroupMember -Identity "Terminal Server License Servers"
$termLicenseServers|Select-Object -Property @{label='computername';expression={[regex]::match($_.DistinguishedName,'([\w\d-]+)(?=,OU=)').Value}}
# Legacy commmands that would yield more results about machines with any RDS roles
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
RDS requires certain ports for communication. One must ensure that these are reachable from the clients – use PortQry to test UDP ports and Test-NetConnection to test TCP ports:
TCP/135 – Microsoft RPC
UDP/135 – Microsoft RPC
UDP/137 – NetBIOS Datagram Service
UDP/138 – NetBIOS Name Resolution
TCP/139 – NetBIOS Session Service
TCP/445 – SMB
TCP/49152–65535 – RPC dynamic address range
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:
# 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
# Short-cut to Microsoft Licensing Manager
licmgr.exe

Categories: