Simpatie.ro - matrimoniale
Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Nou pe simpatie:
sexyindianca
Femeie
24 ani
Ilfov
cauta Barbat
24 - 53 ani
Mrrrr's Forum (VIEW ONLY)ReguliInregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides /

[WINDOWS] Extract Logon and Logoff Times to Notepad

Pagini: 1 Moderat de TRaP, TonyTzu
#1
Mrrrr
AdMiN
Postari: 2388
I just adapted the code from Source 1 a bit in order to export to txt instead of csv, and then open the txt file.

Notepad will contain times and Logon/Logoff IDs, which are:
ID 7001 = Logon
ID 7002 = Logoff

First off, copy the following code to notepad and save the file with ps1 extension, eg. D:\Get Login-Logon Times.ps1


$filter = @{
    Logname = 'System'
    ID = 7001, 7002
    ProviderName = 'Microsoft-Windows-Winlogon'
}
Get-WinEvent -FilterHashtable $filter -MaxEvents 50 |
     Select TimeCreated, ID |
     Out-File D:\Times.txt

Start notepad D:\Times.txt


You cannot open the ps1 file with double click for security reasons.
But you can bypass that by creating a shortcut (New - Shortcut) with the following syntax for the item location. Then double click the shortcut to generate and open the notepad file.


powershell.exe -command "& 'D:\Get Login-Logon Times.ps1'


If using the above command the shortcut doesn't generate and open the txt file, see the post below.

Sources:
1. https://social.technet.microsoft.com/Fo ... powershell
2. https://stackoverflow.com/questions/101 ... a-ps1-file


_______________________________________


 
   
#2
Mrrrr
AdMiN
Postari: 2388
Upon a fresh Windows install I found out that the above command won't work.

Tried:
- enabling developer mode
- setting the shortcut to run as administrator

Both didn't work.

What worked was changing a bit the command to the following:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command "& 'D:\Get Login-Logon Times.ps1'


And for an even shorter powershell window display:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -WindowStyle hidden -Command "& 'D:\Get Login-Logon Times.ps1'


And without showing any window (except for the windows terminal appearing shortly on taskbar) you can pass it through cmd:

cmd.exe /c start /min "" C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command "& 'D:\Get Login-Logon Times.ps1'


Spurce:
https://stackoverflow.com/questions/180 ... g-a-window


_______________________________________


 
   
#3
Mrrrr
AdMiN
Postari: 2388
In Task Scheduler, to open the script at startup, under Actions:

Program/script: cmd.exe
Additional arguments: /c start /min "" C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command "& 'D:\Get Login-Logon Times.ps1'

More options:
https://stackoverflow.com/questions/106 ... ot-running


_______________________________________


 
   
Pagini: 1  
Mergi la