hvbackup and powershell script to email

Jun 10, 2013 at 3:28 PM

I am using a simple .bat file to backup Hyper-V to an external NAS nightly. I was wanting to configure email notification on Windows Server 2012 which appears not to be available for scheduled tasks. Anyhow, I know some people have used blat in their .bat file to send email notification. I would prefer to use powershell to do so and have scripted two powershell files (one for success and one for failure) that successfully send when I execute them. However, scripting them into the pre-existing .bat file does not appear to work and since I am new to scripting, I would appreciate your advice on how I could get this to work. What I basically did was tried to use the script for blat while simply replacing all blat lines with reference to my powershell script. Here is my code:

set BCKPATH="\backup\Volume_1"

rem net use %BCKPATH% /user:<myusername> <mypassword>

pushd %BCKPATH% && forfiles.exe -m *.zip -d -7 -c "cmd /c del @path" popd HVBackup.exe -a -o %BCKPATH% 1> %BCKPATH%\%computername%_lastlog_out.txt 2> %BCKPATH%\%computername%_lastlog_err.txt && set error=0 || set error=1

if ["%error%"] EQU ["1"] (
powershell -noexit "& "C:\backup\send_email.ps1"
if ["%error%"] EQU ["0"] (
powershell -noexit "& "C:\backup\send_email2.ps1"
goto exit
exit /b