Before sending License reports to Mail . I did try this directly on the license server as a means fo debugging PS C:\Windows\system32> Invoke-WmiMethod -Class Win32_TSLicenseReport -Name GenerateReportEx
and it returned the following
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
FileName : PER-USER_20160524-213433-748.dat
ReturnValue : 0
PSComputerName :
Suspecting the license server database is corrupt. Any recommendations ? Will a database rebuild be required at this point. Any suggestions will be appreciated.
John zuh.
This is not a PS issue or code issue, which is what we are here to help with. Well, you have not shown your PS report and mail message code / issues with it.
It is a potential environment issue as noted by you. So, this would not be the correct forum for this question. I'd suggest SuperUser and following this discussion and answer.
The problem A license database for remote desktop in Windows 2012 got corrupted as helpdesk executes several times an script in powershell used to install licenses for Windows 2008 R2 and then for Windows 2012
https://superuser.com/questions/1028042/how-to-fix-a-corrupted-rds-licenses-database
So, since you already suspect environment issues, then correct those in the most prudent methods supported, if it is beyond what the above addresses.
Update for resources
As noted there are additional resources to help you. Take the default reporting class, generate the report and attach that to an email either as a text file or html. At that point, you are just using the basic of the Send-MailMessage cmdlet.
Win32_TSLicenseReport class Provides instances of Remote Desktop Services Per User client access license (RDS Per User CAL) usage reports that are generated on the Remote Desktop license server, and methods for license report generation, fetch, and delete operations.
[dynamic, provider("Win32_WIN32_TERMSERVLICENSING_Prov"), AMENDMENT]
class Win32_TSLicenseReport
{
string FileName;
uint32 LicenseUsageCount;
uint32 InstalledLicenses;
DATETIME GenerationDateTime;
uint32 ScopeType;
string ScopeValue;
uint32 Version;
};
https://learn.microsoft.com/en-us/windows/desktop/TermServ/win32-tslicensereport
GenerateReport method of the Win32_TSLicenseReport class
[GenerateReport is no longer available for use as of Windows Server 2012. Instead, use GenerateReportEx.]
This method is not supported.
Windows Server 2008 R2 and Windows Server 2008: Generates a current per user license usage report on the Remote Desktop license server.
https://learn.microsoft.com/en-us/windows/desktop/TermServ/generatereport-win32-tslicensereport
As per your comment this one you already know about...
Get-WmiObject Win32_TSLicenseKeyPack class
[dynamic, provider("Win32_WIN32_TERMSERVLICENSING_Prov"), AMENDMENT]
class Win32_TSLicenseKeyPack
{
uint32 KeyPackId;
string Description;
uint32 KeyPackType;
uint32 ProductType;
string ProductVersion;
uint32 ProductVersionID;
uint32 TotalLicenses;
uint32 IssuedLicenses;
uint32 AvailableLicenses;
DATETIME ExpirationDate;
uint32 AccessRights;
string TypeAndModel;
};
https://learn.microsoft.com/en-us/windows/desktop/TermServ/win32-tslicensekeypack
Get RDS licenses issued to all trusted domains
This script will get the RDS licenses issued from the local computer that have been issued to all Trusted domains. The variables on lines 1 through 12 needs to be modified to fit your environment.The below snippet generates the new report. If you don't want it to generate it for https://gallery.technet.microsoft.com/scriptcenter/Get-RDS-licenses-issued-to-87389868
$NewReport = Invoke-Wmimethod -class win32_tslicensereport -name generatereport -argumentlist @(3,0)
FetchReportEntries method of the Win32_TSLicenseReport class Retrieves details of Remote Desktop Services Per User client access licenses (RDS Per User CALs) from the report. Each entry represents a RDS Per User CAL that is currently in use. https://learn.microsoft.com/en-us/windows/desktop/TermServ/fetchreportentries-win32-tslicensereport
You don't say what server version you are on, but. you could also use the Terminal Services Licensing Reporter Tool (Lsreport.exe). Here you would need to write a custom script to run Lsreport.exe tool and parse its output.
You can download the old W2K3ResKit to get it. https://www.microsoft.com/en-us/download/details.aspx?id=17657
lsreport /?
Write information about licenses granted by Terminal Server License Servers.
lsreport [/F filename] [/D start [end]] [/T] [/W] [/?] [serverlist]
/F filename Directs output to be written to a file named filename.
(filename defaults to lsreport.txt)
/D start [end] Prints only licenses that were in force between start
and end. (end defaults to today)
/T Directs only temporary licenses to be written.
/W Directs the hardware id to be written to the text file. (.Net Servers Only)
/? Prints this program summary.
serverlist A list of license servers to query. If not specified,
a list will be obtained from a domain controller.
Examples:
lsreport
lsreport /T NTLS-1 NTLS-2
See also:
Manage Remote Desktop Licensing by using Windows PowerShell https://cloudblogs.microsoft.com/enterprisemobility/2010/04/07/manage-remote-desktop-licensing-by-using-windows-powershell
Remote Desktop Services Provider for Windows PowerShell https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/ee791871(v=ws.10)