I want to monitor the resources used by a script.

Is it possible to have it open task manager and preselect its own line in the details tab?

  • What values are you interrested in? The automatic variable $Pid represents the current instance, so see Get-Process -Id $PID | Format-List * – LotPings Dec 4 at 16:40
  • 1
    @LotPings I think he wants task manager to pop up, go to the details tab and then automatically highlight the powershell.exe of the running script to view the resources used automatically. – Narzard Dec 4 at 19:25
  • @Narzard well, the columns presented/selectable in the details pane of task manager are the same as the properties you get with my above command. PowerShell is not primarily a GUI scripting tool and AFAIK task manager isn't scriptable (well). – LotPings Dec 4 at 19:46
  • 1
    @LotPings right. The only issue I see with your method is that you would have to keep refreshing the command for live values that probably would be fine in another window. I just went to script this the GUI way using .net sendkeys() and it was a disaster – Narzard Dec 4 at 20:10
  • As LotPings points out, there is no way to do this interop with TaskManager. If you choose not the follow LotPings suggestion, and yes you will need to do that refresh, then you need to write you own TaskProcess GUI (WPF/WinForms) and populate/refresh as you would need. If you are really trying control a GUI not created by PowerShell, then use something like AutoIT or the like. – postanote Dec 4 at 21:40

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.