[powershell] get list of logon/logoff of logged user or another on this computer
<script>.ps1 without param -> for the logged user
<script>.ps1 -user toto -> for the user toto
Param([Parameter(Mandatory=$false)][string]$usr) $logs = Get-WinEvent -LogName Security| Where-Object {$_.ID -eq 4634 -or $_.ID -eq 4624} ForEach ($log in $logs) if ($username -ne "") {$Results += New-Object PSObject -Property @{"Time" = $log.TimeCreated; "Event" = $type; "User" = $username};} $Results | Where-Object {$_.User -contains $usr} |
Commenter cet article