Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Tuesday, 19 May 2020

Send Email using PowerShell script

Windows PowerShell is a Windows command-line shell designed for system administrators. We can use Send-MailMessage cmdlet to send an email from PowerShell using SMTP protocol.

Copy below script in notepad, change required parameter and save it as SendMail.ps1

[System.Net.ServicePointManager]::SecurityProtocol = 'Tls,TLS11,TLS12'
$From = "Sender email address"
$To = "recipient’s email address"
$Cc = "cc recipient’s email address"
$Subject = "Your Subject"
$Body = "Message Body"
$SMTPServer = "SMTP Server address"
$SMTPPort = "SMTP Server port"
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential (Get-Credential)

Post saving file, Open PowerShell and run command .\SendMail.ps1


It will prompt you for the login credentials.



Note : 

- This script is 100% working with gmail. You must enable less secure app or need to create app password to use this script.

How to enable less secure App in Gmail. - Click Here.
How to create App Password in Gmail. - Click Here.










Tuesday, 22 March 2016

Set IP Address using command in Windows

Some times require to set large number of static IP address in your company. Rather than setting it manually we can use batch file using "netsh"  command to set IP. After that you need to change IP address in batch file and run it on another Computer. "netsh" is windows utility which allows local and remote configuration of network devices. You can use below command to set IP address.

ipconfig /flushdns
ipconfig /release
netsh interface ip set address "Local Area Connection" static 10.195.82.113 255.0.0.0 10.195.82.1
netsh interface ip set dns name="Local Area Connection" static 8.8.8.8
netsh interface ip add dns name="Local Area Connection" 8.8.4.4  index=2
netsh interface set interface "Local Area Connection" disable
netsh interface set interface "Local Area Connection" enabled

where IP Address is 10.195.82.113 Subnetmask :255.255.0.0 Gateway:10.195.82.1 Primary DNS:8.8.8.8 and Secondary DNS is : 8.8.4.4

You may download script file from Here