hi,<\/p>\n

Advertisement

I have exported disconnected RDP sessions from a server.<\/p>\n

Advertisement

Just trying to figure out how to email those users individually and list of managers<\/p>\n

The CSV header is SessionID that has the email address.<\/p>\n

See script below<\/p>\n

& ‘C:\\Scripts\\MASTER-RDP SESSIONS.ps1’ | Where-Object {($.SessionID = $<\/em>.SessionID + “@domain.com<\/span>”)} |export-csv -NoTypeInformation -Path “C:\\temp\\InactiveSessions.csv”<\/p>\n

<\/a>}<\/h1>\n

#import<\/span> Report<\/p>\n

$report = “C:\\temp\\InactiveSessions.csv”
\n$UserList = Import-Csv $report<\/p>\n

<\/a>Setup email parameters<\/h1>\n

$Subject = “DISCONNECTED SERVER SESSIONS<\/strong>” + $today
\n$priority = “Normal”
\n$smtpServer = “xxxx.xxxx.local”
\n$emailFrom = “
[email protected]<\/a>”
\n$emailTo = “Managers”
\n$EmailBody = “Disconnected Server Sessions”<\/p>\n

Send-MailMessage -To $emailTo -From $emailFrom -SmtpServer $smtpServer -Subject $Subject -Attachments $report<\/p>\n

foreach ($SessionID IN $UserList) {
\nSend-MailMessage -To $SessionID -From $emailFrom -SmtpServer $smtpServer -Subject $Subject -Body $EmailBody}<\/p>","upvoteCount":3,"answerCount":3,"datePublished":"2020-06-10T17:29:21.000Z","author":{"@type":"Person","name":"spiceuser-y2pq8","url":"https://community.spiceworks.com/u/spiceuser-y2pq8"},"suggestedAnswer":[{"@type":"Answer","text":"

hi,<\/p>\n

I have exported disconnected RDP sessions from a server.<\/p>\n

Just trying to figure out how to email those users individually and list of managers<\/p>\n

The CSV header is SessionID that has the email address.<\/p>\n

See script below<\/p>\n

& ‘C:\\Scripts\\MASTER-RDP SESSIONS.ps1’ | Where-Object {($.SessionID = $<\/em>.SessionID + “@domain.com<\/span>”)} |export-csv -NoTypeInformation -Path “C:\\temp\\InactiveSessions.csv”<\/p>\n

<\/a>}<\/h1>\n

#import<\/span> Report<\/p>\n

$report = “C:\\temp\\InactiveSessions.csv”
\n$UserList = Import-Csv $report<\/p>\n

<\/a>Setup email parameters<\/h1>\n

$Subject = “DISCONNECTED SERVER SESSIONS<\/strong>” + $today
\n$priority = “Normal”
\n$smtpServer = “xxxx.xxxx.local”
\n$emailFrom = “
[email protected]<\/a>”
\n$emailTo = “Managers”
\n$EmailBody = “Disconnected Server Sessions”<\/p>\n

Send-MailMessage -To $emailTo -From $emailFrom -SmtpServer $smtpServer -Subject $Subject -Attachments $report<\/p>\n

foreach ($SessionID IN $UserList) {
\nSend-MailMessage -To $SessionID -From $emailFrom -SmtpServer $smtpServer -Subject $Subject -Body $EmailBody}<\/p>","upvoteCount":3,"datePublished":"2020-06-10T17:29:21.000Z","url":"https://community.spiceworks.com/t/powershell-to-email-individual-users-in-a-csv/765615/1","author":{"@type":"Person","name":"spiceuser-y2pq8","url":"https://community.spiceworks.com/u/spiceuser-y2pq8"}},{"@type":"Answer","text":"

Welcome<\/p>\n

If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n

PLEASE READ BEFORE POSTING! Read if you're new to the PowerShell forum!<\/a> .<\/p>","upvoteCount":0,"datePublished":"2020-06-10T19:33:29.000Z","url":"https://community.spiceworks.com/t/powershell-to-email-individual-users-in-a-csv/765615/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"

\n
\n
<\/div>\n\"\" spiceuser-y2pq8:<\/div>\n
<\/blockquote>\n<\/aside>\n

you might have to add another step to query active directory to get the manager proprty and get the manager email that waye.g.<\/p>\n

foreach ($SessionID IN $UserList) {\nSend-MailMessage -To $SessionID `\n-cc ((get-aduser $sessionID -properties manager | foreach {get-aduser $_.manager -properties emailaddress).emailaddress})`\n-From $emailFrom -SmtpServer $smtpServer -Subject $Subject -Body $EmailBody\n} \n<\/code><\/pre>","upvoteCount":0,"datePublished":"2020-06-10T19:58:34.000Z","url":"https://community.spiceworks.com/t/powershell-to-email-individual-users-in-a-csv/765615/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}}]}}