【发布时间】:2026-01-11 16:45:01
【问题描述】:
这一切都在 powershell 4.0 中 我们目前有这个脚本,我们每周手动运行一次,它告诉我们网络上所有用户的密码将在
#get max password age policy
$maxPwdAge=(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days
#expiring in 7 days
$7days=(get-date).AddDays(7-$maxPwdAge).ToShortDateString()
Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False - and PasswordLastSet -gt 0} –Properties * | where {($_.PasswordLastSet).ToShortDateString() -le $7days} | Select-Object -Property "Displayname"
这会在运行时显示名称列表。然后我想获取它生成的名称列表,添加字符串“@example.com”以获得字符串“user.name@example.com”
我想向该电子邮件地址发送电子邮件
$EmailFrom = "noreply@domain.com"
$EmailTo = "destinyemail@domain.com"
EmailTo 需要为每个人更改。甚至可以在一封电子邮件中将上述输出通过电子邮件发送给所有用户。
$EmailSubject = "PasswordExpiring"
$emailbody = " body message "
$SMTPServer = "smtpserver.company.com"
Send-MailMessage -Port 587 -SmtpServer $SMTPServer -From $EmailFrom -To $EmailTo -Attachments $emailattachment -Subject $EmailSubject -Body $emailbody -Bodyashtml;
【问题讨论】:
-
this 的最后几行可能有帮助吗?
-
从这里开始 "Powershell Send-MailMessage" technet.microsoft.com/en-us/library/…
-
我已经编辑了帖子以包含最后几行。我很困惑如何编写将根据第一部分检索的用户名更改电子邮件目的地的内容?
标签: powershell scheduled-tasks powershell-4.0