Here is a litle script i’ve build by digging through differents article to match what i needed :


#Extracting the date
$day = get-date -Format dd
$month = get-date -format MM
$year = get-date -format yy
$hour = get-date -Format hh
$min = get-date -Format mm
$today = $day+$month+$year+"-"+$hour+$min
$myFile = "c:\DATA\stats" + $today + ".txt"

#Getting stats from each zone and send all to the text file
Get-DnsServerZone | select zonename | Get-DnsServerStatistics > $myFile

#Sending stats file per email
$PSEmailServer = "email server IP"
Send-MailMessage -From "dnsserver@domain.com" -To "who need the report@domain.com" -Subject $Today" DNS Stats" -Attachments $myFile

First save that into a .ps1 file and then run that through a schedule task with that batch file

@ECHO OFF
PowerShell.exe -Command "& ‘getstats.ps1’"
PAUSE

Tagged with:  

Comments are closed.