Powerscript: How to Get your Public IP Address

For some reason, you want to write a small script to grab your public IP address and email it to you.  Here is one!

$SiteAddress = "http://icanhazip.com"
$HttpContent = Invoke-WebRequest -URI $SiteAddress

###############################################################
$From = "test@gmail.com"
$To = "receipient@gmail.com"
$Cc = "receipient2@gmail.com"
$Attachment = "C:\temp\Some random file.txt"
$Subject = "Email Subject"
$Body = $HttpContent
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"

Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
-Credential (Get-Credential) -Attachments $Attachment

###############################################################

Comments are closed