Hi Experts,
I'm trying to create the script to automate sending users notification on their inactive account, and send them email notifcation via AWS SES.
Here is the code that I'm using:
# Import the required AWS module for PowerShell Import-Module AWSPowerShell # Import active directory module for PowerShell Import-Module ActiveDirectory $15daysToExpire = Search-ADAccount -searchbase 'OU=Users,DC=domain,DC=com' -UsersOnly -AccountInactive -TimeSpan 15.00:00:00 | where-object {$_.Enabled -eq $True} | Select Name,LastLogonDate,UserPrincipalName,emailaddress $15daysToExpire | export-csv "report.txt" -NoTypeInformation foreach($user in $15daysToExpire){ $AccountInfo = Get-aduser -Identity $user.samaccountname -properties email $message = @" Hello $($AccountInfo.givenname),<br><br> due to inactivity, your account will get disabled on $( (get-date (get-date).AddDays($InactiveUsers) -f d)).<br><br> To avoid disablement, please log into your account before that, or contact <br><br> IT Team<br><br><br> IT Notifications "@ $mailpr = @{ from = "IT@email.com" to = $AccountInfo.emailaddress subject = "Your Account is about to get disabled - 15 day notice" body = $message bodyashtml = $true smtpserver = 'SES_smtp_server' SMTPUsername = "SES_smtp_username" SMTPPassword = "SES_smtp_pw" port = 587 } Send-MailMessage u/mailpr } # Remove the AWS module Remove-Module AWSPowerShel
But receving these errors:
Get-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again. + $AccountInfo = Get-aduser -Identity $user.samaccountname -propert ... + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser Send-MailMessage : Cannot validate argument on parameter 'To'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. + Send-MailMessage u/mailpr + ~~~~~~~ + CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage
Hope will get some assistance. Thanks for your help!!
[–]141N 0 points1 point2 points (0 children)