Windows 2012R2 RDS CAL reporting script

Hi, long time we were keeping silent, but not it is a time for some news.

Here i found a script for reporting of per user RDP CAL licenses usage, however my license server was windows 2012r2, so original script was not working. So I changed it to work and also added section to send results by mail, here you go:

# Filename of the export
$filename = “RDS-CAL-Report.csv”
# Import RDS PowerShell Module
import-module remotedesktopservices

# Open RDS Location
Set-Location -path rds:

# Remove previous reports (Optional)
remove-item RDS:\LicenseServer\IssuedLicenses\PerUserLicenseReports\* -Recurse

# Create new RDS report
Invoke-WmiMethod -Class Win32_TSLicenseReport -Name GenerateReportEx

# Name is automatically generated
$NewReportName = Get-ChildItem RDS:\LicenseServer\IssuedLicenses\PerUserLicenseReports -name

# Get issued licenses
$IssuedLicenseCount = get-item RDS:\LicenseServer\IssuedLicenses\PerUserLicenseReports\$NewReportName\Win8\IssuedCount
# Count issued licenses
$IssuedLicenseCountValue = $IssuedLicenseCount.CurrentValue

# Get installed licenses
$InstalledLicenseCount = get-item RDS:\LicenseServer\IssuedLicenses\PerUserLicenseReports\$NewReportName\Win8\InstalledCount
# Count installed licenses
$InstalledLicenseCountValue = $InstalledLicenseCount.CurrentValue

# Installed – Issued
$Available = $InstalledLicenseCount.CurrentValue – $IssuedLicenseCount.CurrentValue
# Show percentage available
$AvailablePercent = ($Available /$InstalledLicenseCount.CurrentValue)*100
$AvailablePercent = “{0:N0}” -f $AvailablePercent

# Display info

Write-host “Installed: $InstalledLicenseCountValue”
Write-host “Issued: $IssuedLicenseCountValue”
Write-host “Available: $Available [ $AvailablePercent % ]”

# Add the information into an Array

[System.Collections.ArrayList]$collection = New-Object System.Collections.ArrayList($null)
$obj = @{
Installed = $InstalledLicenseCountValue
Available = $Available
AvailablePercent = $AvailablePercent
Issued = $IssuedLicenseCountValue
Date = get-date
}

# Exit RDS location
set-location c:

# Create PSO Object with the data
$collection.Add((New-Object PSObject -Property $obj));

# Export Data into a file
$collection | export-csv $filename -NoTypeInformation -Encoding UTF8

#send mail

#Modify to your SMTP server
$smtpServer = “123.12.57.20”

#Modify to your path where report generated
$file = “C:\script\RDS-CAL-Report.csv”
$att = new-object Net.Mail.Attachment($file)
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = “server_reports@microsoft.com”

#Modify recipients

$msg.To.Add(“user1@ms.com”)
$msg.To.Add(“user2@ms.com”)
$msg.CC.Add(“user3@ms.com”)
$msg.Subject = “server licenses usage reporting”
$msg.Body = “Monthly license reporting, refer your question to me”
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()

 

Advertisements

7 thoughts on “Windows 2012R2 RDS CAL reporting script

    1. Unfortunately I do not have any per device license installed.
      In general you should change “PerUserLicenseReports” to something like “PerDeviceUserLicenseReports” everywhere in script.
      Launch powershell session on your TS server where licenses installed.
      Run:
      # Import RDS PowerShell Module
      import-module remotedesktopservices

      # Open RDS Location
      Set-Location -path rds:

      Afterwards you should be able to browse the content for RDS folders and subfolders with “cd” and “dir” commands, this way you can find correct container name for per device licenses

      Like

      1. i thought the same and tried before commenting here, but looks like there is no RDS:\LicenseServer\IssuedLicenses\PerDeviceLicenseReports as RDS:\LicenseServer\IssuedLicenses\PerUserLicenseReports

        Like

  1. In addition when you setup TS server you choose its mode: Per Device or Per User. So you need to check that on TS server, which installed in Per Device mode.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s