{"id":963,"date":"2020-02-18T12:55:11","date_gmt":"2020-02-18T12:55:11","guid":{"rendered":"http:\/\/ihni.uk\/?p=963"},"modified":"2020-02-18T12:55:11","modified_gmt":"2020-02-18T12:55:11","slug":"display-ts-cals-with-powershell","status":"publish","type":"post","link":"https:\/\/ihni.uk\/?p=963","title":{"rendered":"Display TS CALS with PowerShell"},"content":{"rendered":"<p>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.<\/p>\n<p>So instead of emailing them when they remember to ask us for it, I automated it using Powershell.<!--more--><\/p>\n<p>[CC lang=\u2019powershell\u2019]<\/p>\n<p># Short and Nasty Wee script for counting RDS CALs<\/p>\n<p>Push-Location (Split-Path -path $MyInvocation.MyCommand.Definition -Parent)<br \/>\n$Date = Get-Date -Format dd-MM-yy<\/p>\n<p># DCs<br \/>\n$dcs = @(&#8216;DC01&#8242;,&#8217;DC02&#8217;)<br \/>\n$results = @()<\/p>\n<p>$dcs | %{<br \/>\n$cals = GWMI -class win32_TSLicenseKeyPack -computername $_<br \/>\n$results += &#8220;`nServer: `t&#8221; + $_<br \/>\n$results += &#8220;Total: `t`t&#8221; + $cals.totallicenses[1]<br \/>\n$results += &#8220;Available: `t&#8221; + $cals.AvailableLicenses[1]<br \/>\n$results += &#8220;Issued: `t`t&#8221; + $cals.IssuedLicenses[1]<br \/>\n}<\/p>\n<p>$results | SC &#8216;.\\temp\\body.txt&#8217;<\/p>\n<p>$smtpserver = &#8216;mail.yourdomain.uk&#8217;<br \/>\n$emailFrom = &#8216;RDSCALCounter@yourdomain.uk&#8217;<br \/>\n$emailto = &#8216;recipient@yourdomain.uk&#8217;<br \/>\n$subject = &#8220;Monthly CAL Counts&#8221;<br \/>\n$encoding = [System.Text.Encoding]::UTF8<\/p>\n<p>if (Test-Path &#8216;.\\temp\\body.txt&#8217;){<br \/>\n$body = GC &#8216;.\\temp\\body.txt&#8217; -raw<br \/>\nSend-MailMessage -SmtpServer $smtpserver -from $emailfrom -to $emailto -Subject $subject -body $body -Priority high -Encoding $encoding<br \/>\nRemove-Item &#8216;.\\temp\\body.txt&#8217;<br \/>\n}<br \/>\nElse{<br \/>\nSend-MailMessage -SmtpServer $smtpserver -from $emailfrom -to $emailto -Subject $subject -body &#8216;File Doesnt Exist&#8217; -Priority high -Encoding $encoding<br \/>\n}<\/p>\n<p>[\/CC]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a need to provide certain stats every month for our managerial teams on&hellip;<\/p>\n","protected":false},"author":1,"featured_media":988,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[19,11],"tags":[22,67],"class_list":["post-963","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","category-scripts","tag-cals","tag-rds"],"jetpack_featured_media_url":"https:\/\/ihni.uk\/wp-content\/uploads\/2020\/02\/Powershell.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/posts\/963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=963"}],"version-history":[{"count":0,"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/posts\/963\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/media\/988"}],"wp:attachment":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}