Posted On November 14, 2022

PowerShell: Find Windows RDS Roles and Their Licensing Servers

kimconnect 0 comments
blog.KimConnect.com >> Codes , Windows >> PowerShell: Find Windows RDS Roles and Their Licensing Servers
# Get TS Licensing Servers (Enterprise or AD Registered)
$termLicenseServers=Get-ADGroupMember -Identity "Terminal Server License Servers"
$termLicenseServers|Select-Object -Property @{label='computername';expression={[regex]::match($_.DistinguishedName,'([\w\d-]+)(?=,OU=)').Value}}

# Get TS Connection Points with Licensing Role Installed (may or may not be registered on the domain)
$termServers=Get-ADObject -Filter {objectClass -eq 'serviceConnectionPoint' -and Name -eq 'TermServLicensing'}
$termServers|Select-Object -Property @{label='computername';expression={[regex]::match($_.DistinguishedName,'([\w\d-]+)(?=,OU=)').Value}}

# Check localhost for TS Licensing Servers
$tsSettings=gwmi -namespace "Root/CIMV2/TerminalServices" Win32_TerminalServiceSetting 
$tsSettings.GetSpecifiedLicenseServerList().SpecifiedLSList

# Find RDS Servers and their Licensing Configs
$servers=Get-ADComputer -Filter {OperatingSystem -Like '*Windows Server*' -and Enabled -eq $true}
$results=@()
$noResults=@()
$initCount=0
$serversCount=$servers.Count
write-host "There are $serversCount servers to check..."
foreach($server in $servers.DNSHostName){
	$initCount++
	write-host "$initCount of $serversCount`: $server"
	$rdsRole=try{Get-WindowsFeature RDS-RD-Server -ComputerName $server -EA Ignore}catch{$null}	
	if($rdsRole){
		$rdsRoleInstalled=$rdsRole.InstallState -eq 'Installed'
		if($rdsRoleInstalled){
		$rdsLicenseServer=try{		
			$tsSettings=gwmi -namespace "Root/CIMV2/TerminalServices" Win32_TerminalServiceSetting -computername $server
			$tsSettings.GetSpecifiedLicenseServerList().SpecifiedLSList
		}catch{
			'not configured'
		}
		$result=@{
			computername=$server
			rdsLicenseServer=$rdsLicenseServer
			licensingType=$tsSettings.LicensingName
		}
		write-host "$server has RDS-RD-Server role installed with licensing server(s) $rdsLicenseServer"
		$results+=$result
		}else{	
			write-host "$server doesn't have RDS-RD-Server role installed"
		}
	}else{
		write-warning "$env:computername cannot connect to $server"
		$noResults+=@{
			computername=$server
			connectionProblem=$True			
		}
	}
	#pause
}

$results|%{write-host "$($_.computername)`: $($_.rdsLicenseServer) | $($_.LicensingType)"}
$noResults|%{write-host "$($_.computername)"}

Leave a Reply

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

Related Post

PowerShell: Windows Automated Disk Cleanup

##################################################################################     <#      This script is created to automate the cleanup activity. Doing so will benefit to reduce the size of disk.     This script will perform the following   1. Clear windows temp and user temp folder   2. Empty recycle bin   3. Disk Cleanup   4. Clear CBS cabinet log files   5. Clear downloaded patches   6. Clear downloaded driver   7. Clean download folder      Note:  …

PowerShell: Get Executable Version and File Location

# Quick method to obtain computernames of all nodes in a cluster and adjoin result…

PowerShell: Extract Root Domain from URL

Please note that this function requires an updated variable named $domainsDictionary. Since LTD's are being…