我正在使用两个单独的 powershell 脚本。第一个手动定义指定用户的extensionAttribute15的日期。我们打算通过计划调用第二个,以便在extensionAttribute15日期后 14 天发送一封电子邮件,但我收到“解析查询错误”。它仍会发送电子邮件,但日期参考不起作用。
第一个脚本是:
$username = Read-Host 'Enter username'
$ADuser = Get-ADUser -Filter 'sAMAccountName -eq $username'
$string = Read-Host = 'Please enter a date using the format MM/DD/YYYY'
$Date= [DateTime] $string
Write-Host $date -ForegroundColor DarkYellow
set-aduser $username -replace @{extensionattribute15="$Date"}
Get-ADUser -Identity $username -Properties * | select extensionattribute15
第二个脚本是:
import-module activedirectory
#Show me who
Get-ADUser -filter {extensionAttribute15 -eq (Get-Date).adddays(14) -and Description -like 'Test Do not modify' -and Enabled -eq $True} -Properties * | select CN, extensionAttribute15
$users = Get-ADUser -filter {extensionAttribute15 -eq (Get-Date).adddays(14) -and Description -like 'Test Do not modify' -and Enabled -eq $True} -Properties * | select CN, extensionAttribute15
$users | Foreach-Object{
$message = (Get-Content "C:\Test\reminder.htm" | Out-String )
$message = $message -replace "USRname",$_.GivenName
$message = $message -replace "USRalias",$_.SamAccountName
$message = $message -replace "USRemail",$_.EmailAddress
### SMTP Mail Settings
$SMTPProperties = @{
To = $_.EmailAddress
From = "me@org.org"
Subject = "Reminder: Action Required"
SMTPServer = "mail.org.org"
}
Send-MailMessage @SMTPProperties -Body $message -BodyAsHtml
}
如何最好地将扩展属性定义为日期,然后将其用于在未来日期调用电子邮件?
谢谢!