Created
October 18, 2014 16:43
-
-
Save kral2/e06396d14c12792e8394 to your computer and use it in GitHub Desktop.
Get IPv4 and mail it with gmail in powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quick powershell script to : | |
# Get the IPv4 and send it using gmail smtp server. Handy when there is no local SMTP server available | |
# !! Warning !! You need to provide your credentials in plain text ... | |
$date = (get-date).ToString() | |
# Get IPv4. Quick filter with -like "1*" to exclude IPv6. There should be a better way to do it ... | |
$IP = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -filter "ipenabled=true" | | |
Where { $_.IPAddress -like "1*"} | | |
Select -ExpandProperty IPAddress | select -First 1 | |
## Customize this section | |
$user = "<yourGmailAccount>" | |
$pw = "<yourGmailPwd>" | |
$from = $user | |
$to = "<yourRecipients>" | |
$subject = $date + " | " + "My IP is " + " : " + $IP | |
$body = $subject | |
## Customize this section | |
# PowerShell SMTP section (with SSL support) | |
$SMTPServer = "smtp.gmail.com" | |
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) | |
$SMTPClient.EnableSsl = $true | |
$SMTPClient.Credentials = New-object System.Net.NetworkCredential($user,$pw); | |
$SMTPClient.Send($from,$to,$subject,$body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment