PowerShell script showing all login sessions of users for the last month

Welcome Forums General PowerShell Q&A PowerShell script showing all login sessions of users for the last month

Viewing 3 reply threads
  • Author
    Posts
    • #257051
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Hello,

      As it wrote in the title, I need a script that will show me all login in the Domain.

      i got something but its showing me a generic date and time, Also i need to export it to csv file.

      Get-ADUser -Filter {enabled -eq $true} -Properties LastLogonTimeStamp |
      Select-Object Name,@{n=’LastLogon’;e={[DateTime]::FromFileTime($_.LastLogon)}} | Export-Csv c:\public\logon30days.csv -NoTypeInformation

      what im missing?

       

      Thx for the help!

       

    • #257093
      Participant
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      This is because your output property set from Get-ADUser does not contain LastLogon. You must include it with the -Properties parameter:

       

      • #257174
        Participant
        Topics: 1
        Replies: 2
        Points: 17
        Rank: Member

        thanks for answer,

        when i use your line code, I get the real login of the users that i have entered with, but all users that i havent log in with i get srtrange date and time.
        how do i changing it? i want to see the date and time i have created them.
        if you asking yourself, i got a project in MCSA course.

        thanks again.

         

        .Selfridge 12/31/1600 4:00:00 PM
        David.Sehmi 12/31/1600 4:00:00 PM
        David.Sebastian 12/31/1600 4:00:00 PM
        David.Searle 12/31/1600 4:00:00 PM
        David.Scriven 12/31/1600 4:00:00 PM

         

    • #257183
      Participant
      Topics: 15
      Replies: 1776
      Points: 3,218
      Helping Hand
      Rank: Community Hero

      Display all properties so you can see what you specifically need:

    • #257195
      Participant
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      You are seeing this issue for users who have never logged on. You will need logic to handle that situation. You can check that LastLogon contains a convertible [datetime]format.

      You can run the following to reproduce your issue:

      If you want to substitute the user creation date for when LastLogon is blank, you can output that in your else condition:

      • #257207
        Participant
        Topics: 1
        Replies: 2
        Points: 17
        Rank: Member

        Still showing me the generic time and date.

        if i want to see only the users who logged in. wat i need to change in the code?

Viewing 3 reply threads
  • You must be logged in to reply to this topic.