How to find out which script is being executed?

Mountain Pond 1,576 Reputation points
2022-09-02T21:14:57.527+00:00

Hi,
I'm sure a lot of people have had the same problem. When many scripts are running on a machine and there are times when one of the scripts creates a load on the processor or memory.

I need to find out what the script is. However, in the task manager, we can only observe powershell.exe processes, but it is not clear what script is being executed in this process.

Also Process Monitor and Process Explorer do not show the ps1 filename or path. Because the process is already running and powershell was reading and started executing the script.

If it is not possible to know which script is running. Perhaps there is a way to write processes ID to a log file. Is it possible to find out the ID of the powershell process that initialized the script? What would the script add to the log file, the ID of the process from which it started.

Thank you.

Windows for business Windows Client for IT Pros Devices and deployment Configure application groups
Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 36,291 Reputation points
    2022-09-03T00:24:54.367+00:00

    Add command line to the task manger display.

    237481-image.png

    That will tell you the initiating script. If it calls other scripts, review the code or add a transcript to see what other scripts are being called.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-5.1

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. JimmySalian-2011 42,486 Reputation points
    2022-09-02T21:40:23.813+00:00

    Hi Denis,

    Only setting I can recollect is the PS logging via the GPO, as you already tried procmon and proc explorer. about_logging_windows

    ==
    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.