Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. function passwordExpiryHTML(){
  2. $expiryObject = @()
  3. ForEach($user in $UserList) {
  4. # Converts AD password expiry date to a normal time object
  5. try {
  6. $expiryDate = ([datetime]::FromFileTime($user."msDS-UserPasswordExpiryTimeComputed"))
  7.  
  8. # Calculates remaining time till expiry date from current date
  9. $timeRemains = New-TimeSpan -Start (get-date) -End $expiryDate
  10.  
  11. # Takes remaining days and truncates to allow use of modulo/ display to user
  12. # Selected truncation rather then rounding as showing less days is not really an issue, but too many days is
  13. $remainingDays = [Math]::Truncate($timeRemains.Days)
  14.  
  15. if($remainingDays -ge -365 -and $remainingDays -le 14){
  16.  
  17. $item = New-Object -type PSCustomObject -Property @{
  18. 'Username' = $user.samAccountName
  19. 'Name' = $user.Name
  20. 'ExpiryDate' = $expiryDate.ToString("dd/MM/yyyy hh:mm:ss")
  21. 'RemainingDays' = $remainingDays
  22. 'Photo' = [Convert]::ToBase64String($user.thumbnailphoto)
  23. }
  24.  
  25. $expiryObject += $item
  26. }
  27. }except {
  28. $item = New-Object -type PSCustomObject -Property @{
  29. 'Username' = $user.samAccountName
  30. 'Name' = $user.Name
  31. 'ExpiryDate' = $expiryDate.ToString("dd/MM/yyyy hh:mm:ss")
  32. 'RemainingDays' = "Unknown"
  33. 'Photo' = [Convert]::ToBase64String($user.thumbnailphoto)
  34. }
  35.  
  36. $expiryObject += $item
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement