Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7903945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:52:29+00:00 2026-06-03T09:52:29+00:00

I wrote a script to remotely fetch event logs in PowerShell, but I’m not

  • 0

I wrote a script to remotely fetch event logs in PowerShell, but I’m not a fan of the way the script makes its own event log entries.

Specifically this script grabs several types of event IDs including the logon/logoff events. Recently I was asked to run the script to fetch events for another user, and had to have this data fetched in a few hours. Normally I start the script and let it run for the majority of the day (because there is usually a LOT of data here), but this time to speed up the process, I spun up 4 instances of the script to fetch this data faster than usual. Each instance of the script was looking at a different time frame so that all 4 scripts combined were fetching in the time frame I had been asked for.

Over the course of 3 hours or so, I had over a million different login attempts for my user ID on this remote computer. I had so many logins that I ended up overwriting the event log data I was originally asked to fetch.

Lessons learned, I’m now researching how to make this faster, more efficient, and more reliable.

Here’s the heart of my code, pretty plain and simple, and works for the most part.

$output = Get-EventLog `
    -instanceID 4672,4647,4634,4624,4625,4648,4675,4800,4801,4802,4803 `
    -logName Security `
    -after (Get-Date $inStartDate) `
    -before (Get-Date $inEndDate).addDays(1) `
    -message ("*" + $InUserID + "*") `
    -computerName $inPCID

I guess there are several questions that I haven’t been able to figure out in my research thus far. Why would Get-EventLog need to make so many connections? Is it because the connection kept dropping or something?

What would be the fastest way to fetch this data – Using the native Get-EventLog command by specifying a -ComputerName, or should I be using something like Enter-PSSession or Invoke-Command.

Will Enter-PSSession and Invoke-Command both have the same problem I’m having with Get-EventLog?

I’d like to avoid using Enter-PSSession and Invoke-Command for the simple fact that I can’t guarantee all machines in the company will have remote-execution enabled.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:52:30+00:00Added an answer on June 3, 2026 at 9:52 am

    So, the problem was that Get-EventLog was ultimately wiping the remote event logs I was trying to fetch. Not sure why, but Get-EventLog made over a million “connections” that appeared as logon/logoff events, thus overwriting my logs.

    Per @Richard’s comment, I did a bit of research, and decided to test using Get-WinEvent, the updated and more powerful replacement for Get-EventLog. After testing around with this for a week, the worst case scenario that I ran into was my script creating 4 logon/logoff events. This is completely acceptable and much nicer than over a million events.

    A side question I had related to this topic was performance. Because we’re gathering many remote logs, we sometimes need this done as fast as possible. My question is whether or not Get-WinEvent would be fast enough to pull logs, when compared to an Enter-PSSession or an Invoke-Command.

    For the scope of this question, Get-WinEvent satisfied both the speed requirements as well as the event requirements and relying on the cmdlet to perform my remoting worked great.

    My code is pretty simple, but I’ll post it for record reasons:

    Get-WinEvent `
        -computerName $inPCID `
        -FilterHashtable @{LogName="Security";Id=4672,4647,4634,4624,4625,4648,4675,4800,4801,4802,4803; `
                           StartTime = $inStartDate; EndTime = $inEndDate} | Where-object {$_.message -like ("*" + $InUserID + "*")} `
        | export-csv $fullOutputFile
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have wrote a script to produce an array of data but now want
I wrote a script to check my own websites with LWP::RobotUA. I would like
I wrote this script which counts occurrences of particular pattern in a given file.
I wrote a script that uses xcodebuild to generate an AdHoc build of an
I wrote this script to for a contact form on my website, everything works
I recently wrote a script which queries PyPI and downloads a package; however, the
I have wrote a script to do some backup. There is a if block
to custom validate an input i wrote a script: function cardNumberCheck(value, element) { var
I wrote a perl script a while ago which logged into my online banking
I wrote an autocompletion script for an input field on a website. It uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.