Powershell commands on multiple windows

How could be possible to run powershell commands piped to specific PIDs on a text file on C:\PIDs.txt?

the PIDs.txt would be something like


This is a very simple example but would be run “Invoke-Command -ScriptBlock {Get-EventLog system -Newest 50}” and "Get-Content “C:\Services.txt” on all the open powershell windows


Welcome to the forum. :wave:t4:

I’m unsure what actually your question is. Could you please elaborate a little more detailed? And you may explain what the actual goal is - not the way you think you need to go to reach the goal. :wink:

Is it the same question like this one here:

Thank you Olaf for your reply. I’m trying to run some commands as admninistrator and for that I have a powershell script that calls a ps1 file and run some commands but when I run it, it opens a powershell window as administrator and the commands run on the powershell window from the ps1 was called and not on the windows as administrator.

The idea was to get the powershell processes PIDs and somehow running the powershell script using those PIDs but I don’t know how can that be done or if there is any an easier way to do this.

That is still the way you think you should go. What do you actually want to do?

If you run an elevated PowerShell console all processes - including another PowerShell console - you’d run from this elevated PowerShell console would run elevated.

If your question is how to bypass the UAC than the answer is “you cannot bypass the UAC”. If you don’t have administrative rights you cannot do administrative tasks. :wink:

BTW: It would be easier to help when you shared your script instead of describing it in a long-winded way. :wink: