active directory - Find users from AD OU and for each user find Logon and Logout Times in Eventlogs -
i searching script takes users ou of active directory as
$searchbase = "ou=users,ou=abc,ou=gardezi,dc=gardezi,dc=com" $searchtree = "ou=xxdepartment,", "ou=csdepartment," foreach ($ou in $searchtree) { write-host "searching in ou: $ou $searchbase" $name = $ou $name = $name.substring($name.indexof("=")+1,$name.indexof(",")-3) }
and each user find logon , logoff times through eventlog on 2 of computers during last week. logon requirement should meet eventid=4624 , logon type=2 0r 10 as
(($_.instanceid -eq 4624) -and ($_.message -match "logon type:2")) -or (($_.instanceid -eq 4624) -and ($_.message -match "logon type:10")
for 7 days.
can 1 please complete me?
when in doubt, read documentation. get-eventlog
cmdlet has parameter -computername
accepts list of computer names. time range can restricted via -before
, -after
parameters.
$username = 'foo' $hosts = 'hosta', 'hostb', ... $age = (get-date).adddays(-7) get-eventlog -log security -computer $hosts -instanceid 4624 -after $age | ? { $_.message -match "account name:\s+$username\s" -and $_.message -match 'logon type:\s+(2|10)\s' }
Comments
Post a Comment