MASIGNCLEAN101

Get Computername, Username, Date/time of Login in Powershell Updated FREE

Get Computername, Username, Date/time of Login in Powershell

  • Remove From My Forums

 locked

AD login details

  • Question

  • Hi ,

    nosotros are using Windows server 2008 , information technology has around 200 users in Advertizing. Now we need one written report , when users are logging in to their systems in the morning time and when they are loggig off from the Ad.

    I search on the google and establish some vbscript but I would like to know some open source program , which can provide u.s.a. good user friendly report in excel file.Also I would like to implement the same logging in logging out time inside the lync messenger too.

    You can suggest whatsoever third party tool too equally any open up source too.

    Cheers

Answers

    • Proposed every bit answer past Tuesday, December i, 2015 ane:fifty AM
    • Marked equally respond by Mary Dong Th, December 3, 2015 2:04 AM
  • Yous can also specify a logoff script in a GPO. If you use the same shared log file for both logon and logoff events, a script can read the log file and document each logon session, outputting the user, reckoner, starting time fourth dimension, terminate time, and time elapsing of the session. I like to create a comma delimited file, so it can too exist read into a spreadsheet where yous tin can sort by user, computer, date, etc. For case. I take used a logon script batch file similar to:

    @echo off echo Logon,%date%,%time%,%computername%,%username% >> \\myserver\myshare\LogFile.log                    

    The logoff script would exist the same, except the first field would be "Logoff".


    Richard Mueller - MVP Directory Services

    • Marked as answer by Mary Dong Thursday, December 3, 2015 2:04 AM
  • A PowerShell script to parse the log file created by the batch files I posted before could be every bit follows:

    # ParseLogons.ps1  # Specify the shared log file. $FileName = "\\MyServer\MyShare\LogFile.log"  # Hash table of user sessions. $LogonSessions = @{}  # Retrieve the log file. $LogFile = Import-Csv -Path $FileName -Header "Action","Date","Time","Computer","User"  # Read each line of the log file. ForEach ($Line In $LogFile) {     $Action = $Line.Action     $Date = $Line.Date     $Time = $Line.Time     $DateTime  = Get-Date("$Engagement $Time")     $Calculator = $Line.Calculator     $User = $Line.User     $Session = "$Reckoner\$User"     # Check if this is a logon or logoff outcome.     If ($Activeness -eq "Logon")     {         # Check if the concluding event for this session was a logon.         If ($LogonSessions.ContainsKey($Session))         {             # Logoff consequence missing for previous logon issue.             $PreviousTime = $LogonSessions[$Session]             "$Session,$PreviousTime,(unknown),(unknown)"         }         # Add this session to the hash tabular array.         $LogonSessions.Add together($Session, $DateTime)     }     If ($Activity -eq "Logoff")     {         # Check if the last issue for this session was a logon.         If ($LogonSessions.ContainsKey($Session))         {             # Calculate timespan user was logged on.             $PreviousTime = $LogonSessions[$Session]             $Elapsing = [Timespan]($DateTime - $PreviousTime)             "$Session,$PreviousTime,$DateTime,$Duration"             # Remove this session from the hash table.             $LogonSessions.Remove($Session)         }         Else         {             # Previous logon event missing.             "$Session,(unknown),$DateTime,(unknown)"         }     } }  # Loop through the sessions to discover users even so logged on. ForEach ($Entry In $LogonSessions.Keys) {     $PreviousTime = $LogonSessions[$Entry]     "$Entry,$PreviousTime,(still logged on),(unknown)" }                    

    This outputs one line per logon session (combination of computer and user). It documents the session (computername\username), the logon time, the logoff fourth dimension, and the elapsed time for the session. It outputs to the console so you can redirect to a file. The output will be comma delimited, so it can be read into a spreadsheet.


    Richard Mueller - MVP Directory Services

    • Marked equally answer by Mary Dong Thursday, December iii, 2015 two:03 AM

Get Computername, Username, Date/time of Login in Powershell

DOWNLOAD HERE

Source: https://social.technet.microsoft.com/Forums/en-US/75eb5fc3-29cf-408e-8c5b-d634259643ff/ad-login-details?forum=winserverDS

Posted by: acknewstodaygdk.blogspot.com

Share This :