我是Powershell的新手,我想知道是否有人能帮助我。我试图发送带有广告用户组的html电子邮件给他们的经理。
我的问题是:
该表仅包含AD组名称列和说明。我还希望它包含用户的全名和职务。
我的另一个问题是,我还希望脚本在发送之前验证用户或经理的电子邮件是否存在。如果不存在,返回一个错误消息,然后重试。
如果有人能帮助我,我将非常感激。这将帮助我更好地了解和提高自己。
感谢您发送编修。
$UserName = (Read-Host "Username").trim()
$EmailSuperior = (Read-Host "Email address of superior") #or if we can just type de samaccountname it will be perfect
$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>"
# Get group memberships from reference user
$adUser = Get-ADUser -Filter "SamAccountName -eq '$($UserName)'" -Properties Name, Title, Manager, MemberOf
# Define parameters for mailing and send mail to IT-responsible person to review access
$MemberOf = Get-ADPrincipalGroupMembership -Identity $UserName| Get-ADGroup -Properties * | Select name, description | Sort-Object -Property name | ConvertTo-Html -Head $style
$SmtpServer = 'mail.contoso.com'
$FromSender = 'no-reply@contoso.com'
$Subject = 'Review Access: ' + $UserName
# Email Body Set Here
$Body ="
Hello,<br>
<br>
We ask that you verify if these groups are to remain or if any need to be removed with their change of position.<br>
<br>
<br>
$MemberOf
<br>
"
Send-MailMessage -SmtpServer $SmtpServer -From $FromSender -To $EmailSuperior -Bcc $FromSender -Subject $Subject -Encoding "UTF8" -Body $Body -BodyAsHtml
1条答案
按热度按时间vuktfyat1#
我喜欢使用
pscustomobjects
创建如下报告:并获取经理电子邮件: