Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region title check. Get all users which have testjob in their job title
- $users = Get-ADUser -Filter {title -like "testjob" -and enabled -eq $true -and name -notlike "random*" -and name -notlike "Dave"} -server server.pri:3268 -pr AccountExpirationDate, accountExpires,department,company
- foreach ($user in $users)
- {
- if ($user.AccountExpirationDate -eq $null)
- {
- $row = $table.NewRow()
- $row.Name = $user.name
- $row.Department = $user.Department
- $table.Rows.Add($row)
- $arr += @($user.name, $user.Department)
- }
- }
- #endregion
- $body = "The following accounts do not have a expiry date set.</br></br>"
- $body += "Please can someone confirm the end dates for each and add an expiry date to that account.</br></br>"
- $body += Convert-DatatablHtml -dt $table
- $body += "<br><br>🐾"
- if ($table.Rows.Count -eq 0)
- {
- $body = "All accounts currently have an end day set.<br><br>🐾"
- }
- Send-Mailmessage -smtpServer "server.local" -from "email@email.com" -to "email@email.com" -subject "Account Expiries" -body $body -bodyasHTML -priority High
- Send-Mailmessage -smtpServer "server.local" -from "email@email.com" -to $user -cc "email@email.com" -subject "Account Expiries" -body $body -bodyasHTML -priority High
Add Comment
Please, Sign In to add comment