Monday, July 02, 2012

Counting Quest Defender Tokens

A customer wrote a PowerShell script to perform this task. I've cut-and-paste the PoSh script from his original post below in case you’re interested…

Thank you Mr. Torr!

Technorati Tags: ,,

#—————————————————————————-
# Author: Darin Torr
# Contact: darin@colorado2cambodia.com
#
# This script connects to Quest Defender Reporting Console then parses the xml
# to extract token license counts and emails results
#
# Current Version: v1.1
# Version History
#
#
# 5/06/2012 – v1 – Initial Revision.
# 5/06/2012 -v1.1 – Added html and xml file cleanup on report server
#—————————————————————————-

# // Uncomment this to create secure password
#$secureString = Read-Host -AsSecureString
#ConvertFrom-SecureString $secureString | out-file c:\encrypted.txt
#$secure = gc C:\encrypted.txt | ConvertTo-SecureString

# // This is to clean up any old xml and html files from running reports
$reporthtml = “C:\Program Files (x86)\Quest Software\Defender\Defender Report Console\downloads\html\*.html”
$reportxml = “C:\Program Files (x86)\Quest Software\Defender\Defender Report Console\downloads\*.xml”
if (Test-Path $reporthtml)
{
Remove-item $reporthtml
}
if (Test-Path $reportxml)
{
Remove-item $reportxml
}

# // Change to reflect your servername
$url = “http://server/cgi-bin/d5dsslicensereport.exe?mode=0&xsl=d5licensereport.xsl”
# // create a request
[Net.HttpWebRequest] $req = [Net.WebRequest]::create($url)
$req.Method = “GET”
$req.Timeout = 600000 # = 10 minutes

# // Set if you need a username/password to access the resource
$secure = gc C:\encrypted.txt | ConvertTo-SecureString;
$UserName = “domain\username”;
$req.Credentials = New-Object System.Management.Automation.PSCredential($UserName, $secure);

# // Reading data from page
[Net.HttpWebResponse] $result = $req.GetResponse()
[IO.Stream] $stream = $result.GetResponseStream()
[IO.StreamReader] $reader = New-Object IO.StreamReader($stream)
[string] $output = $reader.readToEnd()
$stream.flush()
$stream.close()
$output | out-null
[xml]$defxml = $output
$final = $defxml.defender_license.desktop_license | select Type,Assigned,Allocation | ConvertTo-Html
function SendMail
{
#Mail Variables
$EmailFrom = “who@ever.com>”
$EmailSubject = “Daily Defender Token Count”
$smtpServer = “relay”
$SendTo = “you@yours.com”
$date = (Get-Date -format “MM-dd-yyyy”)

$mailmessage = New-Object system.net.mail.mailmessage

############## MAIL BODY #############

# Update body with any text you want and variables # #
######################################

$body = “
<lang=EN-US link=blue vlink=purple><div><p>
<span style=font-size:10.0pt;font-family:tahoma,sans-serif;color:#595959>
<dd><p><b>Defender Token count as of $date </b>
<p>
<p><pre style=font-size:10.0pt;font-family:tahoma,sans-serif;color:black> $final <b style=color:red></b></pre>
<p>
</dd></span></b></p>”
#Mail info
$mailmessage.from = $emailfrom
$mailmessage.To.add($sendto)
$mailmessage.Subject = $emailsubject
$mailmessage.Body = $body
$mailmessage.IsBodyHTML = $true
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.Send($mailmessage)

}
SendMail

No comments: