Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

HTML Email - Multiple Commands

$
0
0

Hi all,

Let me preface this by saying I don't know much about PowerShell. However, we needed a couple projects tasks done and I took them on to use the opportunity to gain some insight and skills. So my knowledge consists of the one completed project I completed earlier in the day, in combination with the 5-6 hours I've spent searching the Web for help and information.

What I want to do is list the members of the Administrators, Domain Admins, and Enterprise Admins groups. I would like to format the information into three tables in a single email, and use task scheduler to run this and send the report once per week.

I've been successful in displaying the list of one group in a formatted table and I know how to schedule the task. But, I have not been able to get the remaining two groups to output into a table in the same email (they get outputted in the powershell window).

Here's my code:

import-module ActiveDirectory
$smtpServer = "smptServer.com"
$smtpFrom = "youraccount@yourdomain.com"
$smtpTo = "theiraccount@theirdomain.com"
$messageSubject = "Subject Goes Here"

$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true


$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "</style>"

$message.Body = Get-ADGroupMember -Identity "Administrators" | Select-Object Name,SamAccountName | ConvertTo-Html -Head $style	

$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)

Basically, for Get-ADGroupMember -Identity "Administrators" I want the same thing but for "Domain Admins" and "Enterprise Admins" as well.

Can anyone help me out? Any help is much appreciated.



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>