@@ -37,6 +37,10 @@ $users = Get-LocalUser | Select *
3737$pathUsers = " C:\Users"
3838$allUsers = @ ()
3939
40+ $startTime = (get-date ).AddDays(-15 )
41+ $logEvents = Get-Eventlog - LogName Security - after $startTime | where {$_.eventID -eq 4624 }
42+
43+
4044foreach ($user in $users ) {
4145 if ($user.Name -ne $null ){
4246
@@ -45,6 +49,25 @@ foreach ($user in $users) {
4549 $folderSize = Get-Size $path
4650 if ($user.Enabled -ne " False" ) { $userStatus = " Disabled" } else { $userStatus = " Enabled" }
4751 if ($userType -eq " Local" ) { $userType = $user.PrincipalSource }
52+
53+ $numberConnexion = 0
54+ $workstation = " "
55+ $numberRemoteConnexion = 0
56+ $ipRemote = " "
57+
58+ foreach ($userconnection in $logEvents ){
59+ # In local logon
60+ if (($userconnection.ReplacementStrings [5 ] -eq $user.Name ) -and (($userconnection.ReplacementStrings [8 ] -eq 2 ) -or ($userconnection.ReplacementStrings [8 ] -eq 7 ))){
61+ $numberConnexion = $numberConnexion + 1
62+ $workstation = $userconnection.ReplacementStrings [11 ]
63+ # In remote
64+ }if (($userconnection.ReplacementStrings [5 ] -eq $user.Name ) -and ($userconnection.ReplacementStrings [8 ] -eq 10 )){
65+ $workstation = $userconnection.ReplacementStrings [11 ]
66+ $numberRemoteConnexion = $numberRemoteConnexion + 1
67+ $ipRemote = $userconnection.ReplacementStrings [18 ]
68+ }
69+ }
70+
4871
4972 $xml += " <WINUSERS>`n "
5073 $xml += " <NAME>" + $user.Name + " </NAME>`n "
@@ -56,6 +79,9 @@ foreach ($user in $users) {
5679 $xml += " <USERMAYCHANGEPWD>" + $user.UserMayChangePassword + " </USERMAYCHANGEPWD>`n "
5780 $xml += " <PASSWORDEXPIRES>" + $user.PasswordExpires + " </PASSWORDEXPIRES>`n "
5881 $xml += " <SID>" + $user.SID + " </SID>`n "
82+ $xml += " <USERCONNECTION>" + $numberConnexion + " </USERCONNECTION>`n "
83+ $xml += " <NUMBERREMOTECONNECTION>" + $numberRemoteConnexion + " </NUMBERREMOTECONNECTION>`n "
84+ $xml += " <IPREMOTE>" + $ipRemote + " </IPREMOTE>`n "
5985 $xml += " </WINUSERS>`n "
6086
6187 $allUsers += $user.Name
0 commit comments