Issues Finding last logged on user

Welcome Forums General PowerShell Q&A Issues Finding last logged on user

Viewing 0 reply threads
  • Author
    Posts
    • #211965
      Participant
      Topics: 1
      Replies: 0
      Points: -7
      Rank: Member

      Just started a new job, and the previous guy was really bad about updating our documentation.  We are trying to get that fixed. I was trying to start with figuring out who has what computer. Initially I was just checking the last modified user file. However, I was getting an abnormally high amount of computers just not answering.

      I came up with the script below next. If I run the script on a specific computer, it works, but I can’t get it to work right when pulling from the CSV.  Computers that I know are on, just don’t answer, or it says it can’t find the path. I’m still brand new to using powershell, and have run out of ideas. Any help would be appreciated.

      $computers = import-csv "C:\temp\computerlist.csv"
      $outputfile = "C:\temp\Systems-With-Last-User.txt"
      foreach ($computer in $computers){
      $computername = $computer.'computername'
      write-host "Begin $computername"
      add-content $outputfile "Begin $computername"
      Get-Service -ComputerName $computername -Name RemoteRegistry | Set-Service -StartupType Manual
      Get-Service -ComputerName $computername -Name RemoteRegistry | start-Service
      REG QUERY \\$computername\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI /v LastLoggedOnUser | out-file -append $outputfile -Encoding utf8
      add-content $outputfile "End $computername"
      Get-Service -ComputerName $computername -Name RemoteRegistry | Stop-Service
      write-host "End $computername"
      }
      • This topic was modified 2 months ago by nemessiah03. Reason: spellin/words
      • This topic was modified 2 months ago by nemessiah03.
Viewing 0 reply threads
  • You must be logged in to reply to this topic.