Display TS CALS with PowerShell

Display TS CALS with PowerShell

I have a need to provide certain stats every month for our managerial teams on some of our contracts. One of which is the Terminal Services licensing.

So instead of emailing them when they remember to ask us for it, I automated it using Powershell.

[CC lang=’powershell’]

# Short and Nasty Wee script for counting RDS CALs

Push-Location (Split-Path -path $MyInvocation.MyCommand.Definition -Parent)
$Date = Get-Date -Format dd-MM-yy

# DCs
$dcs = @(‘DC01′,’DC02’)
$results = @()

$dcs | %{
$cals = GWMI -class win32_TSLicenseKeyPack -computername $_
$results += “`nServer: `t” + $_
$results += “Total: `t`t” + $cals.totallicenses[1]
$results += “Available: `t” + $cals.AvailableLicenses[1]
$results += “Issued: `t`t” + $cals.IssuedLicenses[1]
}

$results | SC ‘.\temp\body.txt’

$smtpserver = ‘mail.yourdomain.uk’
$emailFrom = ‘[email protected]
$emailto = ‘[email protected]
$subject = “Monthly CAL Counts”
$encoding = [System.Text.Encoding]::UTF8

if (Test-Path ‘.\temp\body.txt’){
$body = GC ‘.\temp\body.txt’ -raw
Send-MailMessage -SmtpServer $smtpserver -from $emailfrom -to $emailto -Subject $subject -body $body -Priority high -Encoding $encoding
Remove-Item ‘.\temp\body.txt’
}
Else{
Send-MailMessage -SmtpServer $smtpserver -from $emailfrom -to $emailto -Subject $subject -body ‘File Doesnt Exist’ -Priority high -Encoding $encoding
}

[/CC]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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