I'm using two separate powershell scripts. The first one manually defines a date for the specified user's extensionAttribute15. The second one we intend to invoke via schedule to send an email 14 days from the extensionAttribute15 date but I'm getting "Error parsing query". It still sends the email but the date reference isn't functional.
First script is:
$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
Second script is:
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
}
How can I best define an extensionattribute as a date then use it for invoking an email at a future date?
Thanks!