E
E
EmachinesDIMA2020-03-19 13:13:46
Python
EmachinesDIMA, 2020-03-19 13:13:46

How to do a table lookup with an Active Directory connection to get a user's email and send that user's values ​​to him?

Hello ! Does anyone have sketches?

There is a csv file with surnames and values.

You need to search by name, connect to AD to get the user's address and send the values ​​to the address downloaded from AD.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-03-19
@EmachinesDIMA

I threw a script, I think what you need.
$users = Import-Csv -Path "C:\test\test.csv" -Encoding Default -Delimiter ","
$AD = Get-ADUser -filter * #Specify
mail server parameters
$EmailFrom = "[email protected]" #you must specify the address on behalf of which letters will be sent
$Subject = "Subject of the letter" #you must specify the subject of the letter
$smtpServer = "smtp.mail.ru" #you must specify the address of the mail server
$smtp = New-Object net.mail.smtpclient( $smtpServer)
###################################
foreach ($user in $users)
{
$username = $user.name
$EmailTo = $ad | where-object {$_.name -like "*$username*" } | Select-Object UserPrincipalName
$EmailTo = $EmailTo.UserPrincipalName
$Monitor = $user.Monitor
$Mouse = $user.Mouse
$Body = "Monitor - $Monitor Mouse -$Mouse"
$smtp.Send($EmailFrom, $EmailTo, $Subject, $Body )
$EmailTo = $Null
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question