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: List All Hyper-V Snapshots of All VMs in All Clusters in Domain

# listHyperVSnapshots.ps1 $clusterName='*' function listAllHyperVSnapshots([string[]]$clusterName){ function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709…

Basic CSS: Give a Background Color to a div Element

<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css"><style>.red-text {color: red;}h2 {font-family: Lobster, monospace;}p {font-size: 16px;font-family: monospace;}.thick-green-border {border-color: green;border-width: 10px;border-style:…

PowerShell: Uninstall Program Using Its Name

# uninstallProgramUsingId.ps1 $appName='Virtual Machine Manager Agent' $uninstallStringRegPaths='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall' $uninstallStrings=Get-ChildItem -Path $uninstallStringRegPaths $uninstallString=($uninstallStrings|Get-ItemProperty|Where-Object {$_.DisplayName -match $appName}).UninstallString if($uninstallString.count…