Posted On October 14, 2020

PowerShell: Get Terminal Service (Remote Desktop Service) Licenses Report

kimconnect 2 comments
blog.KimConnect.com >> Codes >> PowerShell: Get Terminal Service (Remote Desktop Service) Licenses Report
# rdsLicenseReport.ps1
$knownRdsComputers=$null # Options: (a) 'SERVER1','SERVER100' (b) Get-Content Path\To\RDServers.txt

function getTsLicenses{
  param(
    $knownRdsComputers,
    $domain=$env:userdnsdomain
    )
  try{
      import-module activedirectory
      $pdc=(get-addomain -server $domain).PdcEmulator
      $tsLicenseServers=(Get-ADGroupMember -server $pdc -Identity "Terminal Server License Servers"|?{$null -ne $_.distinguishedName}).Name
      if($knownRdsComputers){
        $tsLicenseServers=$tsLicenseServers+$knownRdsComputers|select-object Unique
      }
      $tsLicenses=@()
      foreach ($server in $tsLicenseServers){
          # Class source: https://learn.microsoft.com/en-us/windows/win32/termserv/win32-tslicensekeypack?redirectedfrom
          $tsLicense=Get-CIMInstance -computername $server Win32_TSLicenseKeyPack `
                      -filter "TotalLicenses!=0"|?{$_.TypeAndModel -ne 'Built-in TS Per Device CAL'}
          $tsLicenses+=$tsLicense|select -Property @{n='LicenseServer';e={$_.PSComputerName}},TypeAndModel,TotalLicenses,IssuedLicenses,AvailableLicenses,ProductVersion,ExpirationDate
      }
      return $tsLicenses
  }catch{
      write-warning $_
      return $false
  }
}

getTsLicenses $knownRdsComputers|Format-Table -autosize
PS C:\Windows\system32> getTsLicenses|Format-Table -autosize
LicenseServer TypeAndModel TotalLicenses IssuedLicenses AvailableLicenses ExpirationDate ProductVersion
------------- ------------ ------------- -------------- ----------------- -------------- --------------
NEW-RDS-LicServ RDS Per User CAL 1000 790 210 12/31/2037 5:00:00 PM Windows Server 2016
OLD-RDS1 TS or RDS Per User CAL 400 40 360 12/31/2037 5:00:00 PM Windows Server 2008 or Windows Server 2008 R2
OLD-RDS2 RDS Per User CAL 100 10 90 12/31/2037 5:00:00 PM Windows Server 2003
OLD-RDS3 RDS Per User CAL 50 00 50 12/31/2037 5:00:00 PM Windows Server 2000
# Quick 1-liner Snippet to Get Licensing Server Names
# Discover RDS Licensing Servers in Active Directory
(Get-ADGroupMember -Identity "Terminal Server License Servers"|?{$_.ObjectClass -eq 'computer'}).name

2 thoughts on “PowerShell: Get Terminal Service (Remote Desktop Service) Licenses Report”

Leave a Reply

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

Related Post

PowerShell: Stop Any Service on Windows!

Problem: some system protected services cannot be stopped. PS C:\Users\KingKong> stop-service msmpsvcStop-Service : Service 'Microsoft…

PowerShell: Automatically Log Off Idling Remote Desktop Sessions

Add this script to your task scheduler or Jenkins job to automatically log off Idling…

PowerShell Commands to Discover the Server Network, Netmask, DHCP status, and Gateway

$servername = "SERVER01"get-wmiobject win32_networkadapterconfiguration -computername $servername -ea stop | ? {$_.IPEnabled}# Result:DHCPEnabled      :…
Other project: DragonCoin.com