Question : Powershell Script to query a OU with users and update the Last password reset date and Last used date.

Hi,

Powershell Script to query a OU with users and update the Last password reset date and Last used date.
Like

(Password reset : 10 days) (Last logged in : 5 days)

Regards
sharath

Answer : Powershell Script to query a OU with users and update the Last password reset date and Last used date.


Fixed :)

Chris
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
$DomainControllers = "dc1", "dc2", "dc3", "dc4"

$Users = @{}
$DomainControllers | ForEach-Object {
  Get-QADUser -SearchRoot "domain.com/Offices" -Enabled -Service $_ -SizeLimit 0 | `
    Select-Object DN, LastLogon, PasswordLastSet | ForEach-Object { 
      If ($Users.$($_.DN)) {
        $Users.$($_.DN) = $_ | Select-Object DN, PasswordLastSet, `
          @{n='LastLogon';e={ 
            If ($_.LastLogon -gt $Users.$($_.DN).LastLogon) { 
              $_.LastLogon 
            } Else { 
              $Users.$($_.DN).LastLogon 
            } }}
      } Else {
        $Users.Add($_.DN, $_)
      }
    }
}

$Users.Values | ForEach-Object {
  If ($_.PasswordLastSet -ne $Null) {
    $PasswordReset = (New-TimeSpan $_.PasswordLastSet).Days
  } Else {
    $PasswordReset = "-"
  }

  If ($_.LastLogon -ne $Null) {
    $LastLogon = (New-TimeSpan $_.LastLogon).Days
  } Else {
    $LastLogon = "-"
  }

  Set-QADUser $_.DN -Description "(Password reset : $PasswordReset days) (Last logged in : $LastLogon days)"
}
Random Solutions  
 
programming4us programming4us