Guest User

Untitled

a guest
Sep 7th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #region title check. Get all users which have testjob in their job title
  2. $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
  3. foreach ($user in $users)
  4. {
  5. if ($user.AccountExpirationDate -eq $null)
  6. {
  7. $row = $table.NewRow()
  8. $row.Name = $user.name
  9. $row.Department = $user.Department
  10.  
  11. $table.Rows.Add($row)
  12.  
  13. $arr += @($user.name, $user.Department)
  14. }
  15. }
  16.  
  17. #endregion
  18.  
  19. $body = "The following accounts do not have a expiry date set.</br></br>"
  20. $body += "Please can someone confirm the end dates for each and add an expiry date to that account.</br></br>"
  21.  
  22. $body += Convert-DatatablHtml -dt $table
  23. $body += "<br><br>&#128062;"
  24.  
  25. if ($table.Rows.Count -eq 0)
  26. {
  27. $body = "All accounts currently have an end day set.<br><br>&#128062;"
  28. }
  29.  
  30. Send-Mailmessage -smtpServer "server.local" -from "email@email.com" -to "email@email.com" -subject "Account Expiries" -body $body -bodyasHTML -priority High
  31.  
  32. 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