Powershell RDS CAL email Report

0 votes

I have a PowerShell command that gives me how many CALs I have installed and how many are used.  I want to change the write-host to a variable so that I can add it to a mail.

This is what I have :

$fileName = (Invoke-WmiMethod Win32_TSLicenseReport -Name GenerateReportEx).FileName
$summaryEntries = (Get-WmiObject Win32_TSLicenseReport|Where-Object FileName -eq $fileName).FetchReportSummaryEntries(0,0).ReportSummaryEntries
$summaryEntries|ForEach {Write-Host $_.ProductVersion $_.TSCALType "Installed:" $_.InstalledLicenses "Issued:" $_.IssuedLicenses}

$EmailTo = "itgroup@contonso.com"
$EmailFrom = "admin@contonso.com"
$user = 'admin@contonso.com'
$password = Unprotect-CmsMessage -Path C:\Scripts\Powershell\EncryptedSecret.txt
$Subject = "Alert: CAL USAGE "
$Body = "Alert; $Report"
$SMTPServer = "smtp@contonso.com"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.EnableSsl = $false
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($user, $password)
$SMTPClient.Send($SMTPMessage)


I have used both parts of this script separately, but I would like to join them together, to make them more useful.
Apr 9, 2022 in Others by Kichu
• 19,040 points
1,473 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

+1 vote
1 answer

Create a User Account in Windows 10 with PowerShell.

Hi@akhtar, To create a new user account without ...READ MORE

answered Oct 7, 2020 in Others by MD
• 95,460 points
848 views
0 votes
1 answer

How to Restart Computer with PowerShell?

Hi@akhtar, You can use the Restart-Computer command in ...READ MORE

answered Oct 7, 2020 in Others by MD
• 95,460 points
2,451 views
0 votes
0 answers

Why can't I connect to AWS RDS?

0 I'm trying to connect to my new ...READ MORE

Mar 1, 2022 in Others by Edureka
• 13,690 points
607 views
0 votes
1 answer

Amazon RDS Instance Password?

If you're getting issues when using the ...READ MORE

answered Mar 3, 2022 in Others by gaurav
• 23,260 points
1,038 views
0 votes
1 answer

Exporting a table from Amazon RDS into a CSV file

Presumably, you're attempting to export data from ...READ MORE

answered Mar 3, 2022 in Others by gaurav
• 23,260 points
2,477 views
+6 votes
5 answers

can't remove SSIS variables using remove method on PowerShell

you're missing the additional $environment.Alter() after your ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by ajs3033
• 7,300 points
2,672 views
0 votes
1 answer

Start vNext build from Powershell and get artefacts

TFS 2015 comes with the new REST API, ...READ MORE

answered Jul 5, 2018 in Other DevOps Questions by Kalgi
• 52,350 points
851 views
0 votes
1 answer

How to use Powershell DSC for application installation?

Occasionally folks want to be able to ...READ MORE

answered Jul 16, 2018 in Other DevOps Questions by Kalgi
• 2,680 points
931 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP