Question

I am writing a script in powershell to run automatically once a domain user logs onto a computer. At the completion of the script I want it to send an email to our helpdesk ticketing system, in order to know which user the script ran on, I want to send it from the user's email. Is there a way to pass the credentials from the current logged in user to send an email.

I know on the first startup of Outlook, the fields auto-populate with the user's email address, so I'm looking for something like that.

Was it helpful?

Solution

This is adapted from a method I use in EWS scripts:

$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + '>'
$MailAddress = ([ADSI]$sidbind).mail.tostring()

$MailAddress 

That's assuming you're using an SMTP relay to send the email. Most Exchange orgs will have an Exchange receive connector set up somewhere for application servers and things like MFD's that can't authenticate to the domain to send email to Exchange recipients. Find out where that is an put it into the SMTPServer parameter of Send-MailMessage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top