01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # 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)" } |

November 14, 2022November 14, 2022
0 Comments