Ho uno script che può aiutarti se sei su Windows Server:
function get-logonhistory{
Param (
#get ip(127.0.0.1) and number of days you want get
[string]$Computer = (Read-Host IP remoto do PC),
[int]$Days = (Read-Host number of days)
)
cls
$Result = @()
Write-Host "wait..."
$ELogs = Get-EventLog System -Source Microsoft-Windows-WinLogon -After (Get-Date).AddDays(-$Days) -ComputerName $Computer
If ($ELogs)
{ Write-Host "processing..."
ForEach ($Log in $ELogs)
{ If ($Log.InstanceId -eq 7001)
{ $ET = "Logon"
}
ElseIf ($Log.InstanceId -eq 7002)
{ $ET = "Logoff"
}
Else
{ Continue
}
$Result += New-Object PSObject -Property @{
Time = $Log.TimeWritten
'Event Type' = $ET
User = (New-Object System.Security.Principal.SecurityIdentifier $Log.ReplacementStrings[1]).Translate([System.Security.Principal.NTAccount])
}
}
$Result | Select Time,"Event Type",User | Sort Time -Descending | Out-GridView
Write-Host "Done."
}
Else
{ Write-Host "Problem with ip $Computer."
}
}
#function call
get-logonhistory
Write-Host "Press any key ..."
#stop script to window dont close
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")