Skip to content

Instantly share code, notes, and snippets.

@rbocchinfuso
Last active April 7, 2021 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbocchinfuso/06ad8a9aef58598f3660 to your computer and use it in GitHub Desktop.
Save rbocchinfuso/06ad8a9aef58598f3660 to your computer and use it in GitHub Desktop.
NetWorker Daily Backup Report
<#
NetWorker Daily Status Report
nw_daily_rpt.ps1
Rich Bocchinfuso 2014-10-23
rbocchinfuso@gmail.com
#>
### vars
$ver="0.1"
$date = Get-Date -Format D
## customer info
$cust="FOO"
$site="Chicago"
$nwsvr="CHNetworker1"
## nmc crdentials
$user="administrator"
$pwd="foobar11"
## where to store report files
$reportstore="\\10.10.216.9\chdd4200_bkup_infra\NW_Bkup_Reports\"
## mail settings
$smtprelay="mailhost.foo.com"
$smtpport="25"
$domain="foo.com"
$from="${nwsvr}@${domain}"
#$to="<rbocchinfuso@gmail.com>"
$to="<rec1@foo.com>","<rec2@bar.com>"
$cc=""
# smtp credentials (if auth is required)
$smtpuser = "${nwsvr}@${domain}"
$smtppwd = "password"
## report gen vars
# note: JAVA_HOME must be set in gstclreport.bat script
$gstclrpt="D:\EMC NetWorker\Management\GST\bin\gstclreport.bat"
$rptformat="csv"
$now = get-date -uformat "%Y-%m-%d_%H-%M-%S"
$rpt="/Reports/NetWorker Backup Status/Group Summary by Client and Server"
$rpttmp="rpttmp"
$htmlout="${reportstore}${nwsvr}_Daily_Status_${now}.html"
"Begin Report Script"
try
{
# generate csv report
#write-host "$gstclrpt -u $user -P $pwd -r `"$rpt`" -x $rptformat -o landscape -f `"$reportstore$rpttmp`" -C `"Group Start Time`" `"1 day ago`" -C `"Server Name`" $nwsvr"
& $gstclrpt -u $user -P $pwd -r `"$rpt`" -x $rptformat -o landscape -f `"$reportstore$rpttmp`" -C `"Group Start Time`" `"1 day ago`" -C `"Server Name`" $nwsvr
### convert csv to html
# html report format
$title = "$nwsvr Daily Backup Report"
$style = @"
<style>
TABLE{border-width: 3px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 2px;text-align: center;padding: 10px;border-style: solid;border-color: black;font-family: Arial;color: #FFFFFF;background-color:#08088A}
TD{border-width: 2px;text-align: center;padding: 10px;border-style: solid;border-color: black;font-family: Arial;color: #0A0A2A;background-color: #FAFAFA}
tr.special {background: #000080;} <tr class="special"></tr>
</style>
"@
$rpthead = @"
<font face="Arial"><b>
Customer: $cust<br>
Site: $site<br>
NetWorker Server: $nwsvr<br>
Report Date: $date<br>
</b></font>
"@
#write-host "Get-Content "$reportstore$rpttmp.csv" | select -skip 10 | ConvertFrom-Csv | ConvertTo-Html -head $style | Out-File $htmlout"
Get-Content "$reportstore$rpttmp.csv" | select -skip 10 | ConvertFrom-Csv | ConvertTo-Html -title $title -head $style -body $rpthead | Out-File $htmlout
<#
## email report for powershell < ver 2
$emailMessage = New-Object System.Net.Mail.MailMessage( $from , $to )
$date = Get-Date -Format D
$emailMessage.Subject = " $nwsvr Daily Backup Report - " + $date
$emailMessage.IsBodyHtml = $true
$emailMessage.Body= (Get-Content $htmlout )
$body = (Get-Content $htmlout )
$SMTPClient = New-Object System.Net.Mail.SmtpClient( $smtprelay , $smtpport )
$SMTPClient.EnableSsl = $false
## uncomment the following line if smtp auth is required
#$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $smtpuser , $smtppwd );
$SMTPClient.Send( $emailMessage )
#>
## email report for powershell >= ver 2
$subject = " $customer - $site - $nwsvr Daily Backup Report - " + $date
$body = (Get-Content $htmlout | out-string)
send-mailmessage -from $from -to $to -subject $subject -body $body -bodyashtml -smtpserver $smtprelay
}
catch [system.exception]
{
"caught a system exception"
}
finally
{
"Report Script Complete"
}
@mgayas
Copy link

mgayas commented Sep 5, 2016

Hi,
Thanks for nice script. This is what I was looking for. I am getting an error when I run the script. And I need your help please.
script_error
script_error

@jdix531
Copy link

jdix531 commented Oct 24, 2016

Hey - it took me a few minutes to figure this out but I appreciate this a lot! To the commentor above (more likely, future searchers), you'll notice that it says your "JAVA_HOME" is "" and it says that because the variable needs to be defined in the mentioned batch file: '$gstclrpt="D:\EMC NetWorker\Management\GST\bin\gstclreport.bat"'. In the batch it says it needs JRE 7 - but it actually needs whatever version NW is already using (8.x more likely with new installs, and in my case).

You'll also need to modify one line (on newer versions of networker, as the command changed) -

From:

& $gstclrpt -u $user -P $pwd -r "$rpt" -x $rptformat -o landscape -f "$reportstore$rpttmp" -C "Group Start Time" "1 day ago" -C "Server Name" $nwsvr

To:

& $gstclrpt -u $user -P "$pwd" -r $rpt -x $rptformat -o landscape -f "$reportstore$rpttmp" -C "Workflow Start Time" "1 day ago" -C "Server Name" $nwsvr

This script saved me a ton of time and research. I appreciate your work!

@rajeshr988
Copy link

Am getting below error

PS D:\Program Files\EMC NetWorker\Management\GST\bin> .\gstclreport.bat
Your current JAVA_HOME is

Java Runtime Environment Version 7 is required to run this script.
Please read comments at the top of gstclreport.bat file to set
JAVA_HOME to a valid JRE location.

How to solve this

@suresh3k
Copy link

suresh3k commented Jun 5, 2017

could some one pls help to fix the below issue.
PS D:\Program Files\EMC NetWorker\Management\GST\bin> .\gstclreport.bat
Your current JAVA_HOME is

Java Runtime Environment Version 7 is required to run this script.
Please read comments at the top of gstclreport.bat file to set
JAVA_HOME to a valid JRE location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment