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

Strategies to Free Up Disk Space C:\ Drive

1. Move pagefile away from system drive (optional) 2. Turn off System Restore (warning; this…

System Backup Proposal for Businesses not Under Regulations

Objectives: - RPO 10 minutes for Data of mission critial servers (Domino & Finance) -…

PowerShell: Convert Local Path to UNC Path

function convertLocalToUnc($localPath,$computername){ $uncPath=.{$x=$localPath -replace "^([a-zA-Z])\:","\\$computername\`$1`$"; if($x -match '\\$'){return $x.Substring(0,$x.length-1)}else{return $x} } $validLocal=if($localPath){test-path $localPath -ErrorAction SilentlyContinue}else{$false}…