Script a week – week 00000001
The PowerShell script bellow gets the last login date and the last password set date of enabled users in a particular OU

####Script by Chris of TECHGUYBLOG.CO.UK (C) 2018
####Tested on PS 5.0 AND 6.0
####This gets all active users of a particular OU, 
####Then Outputs a CSV IN # C:\DATA\CurrentDate.csv
####This needs to be run in powershell with administrative permissions
####Requires Active Directory tools installed on the machine
####or to be run on the domain controller
Import-Module ActiveDirectory ####Imports ad tools 
$CurrentDate=GET-DATE -format ddMMyyyyhhmm ##Gets date and formats it
$OU = "OU=Staff,OU=School,DC=Domain,DC=CO,DC=UK"
get-aduser -SearchBase "$OU" -filter 'enabled -eq $True' -properties `
passwordlastset, lastLogon  
#####Gets the user in the OU, And the password last set and last log on info
 | select name, passwordlastset, `
@{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}} ` ####Gets the info
 | export-csv "c:\data\$currentdate.csv" -notypeinformation -Force ####Exports the file

PS Version – Test on 5.0 & 6.0
Server Version – Tested on Windows Server 2012
Administrative Credentials required – Yes
Requires Active Directory Tools – Yes or ran on DC
Changes needed? – Yes $OU (Line 8) Must be changed to fit your set up and you could change the export location on the last line.


This script is part of my script a $week* plan, where every $week* i will post a script that may be useful to use or just pump out some interesting information

 

 

$week* may or may not be a calander week

By Chris