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
12345
123
1234
13452
...
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
Thanks
Powershell commands on multiple windows
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
-
- Posts: 3
- Last visit: Fri Apr 21, 2023 10:16 am
Re: Powershell commands on multiple windows
What is your definition of a PID? Note that a text file cannot be arbitrarily written or read.
Don't say how you want to do this, just describe what the outcome is based on what you have to start and don't use technical words just use plain English.
Don't say how you want to do this, just describe what the outcome is based on what you have to start and don't use technical words just use plain English.
-
- Posts: 3
- Last visit: Fri Apr 21, 2023 10:16 am
Re: Powershell commands on multiple windows
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.
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.
Re: Powershell commands on multiple windows
That is what happens if you open up a new PowerShell session. Why do you need a new session? Note that the new session will also run at the same level as the session that launched the new copy.
If you don't want a new process, then just run the script directly from the current process.
Here is a place to start to understand how PowerShell works and runs commands and processes.
https://www.sapien.com/books_training/W ... werShell-4
If you don't want a new process, then just run the script directly from the current process.
Here is a place to start to understand how PowerShell works and runs commands and processes.
https://www.sapien.com/books_training/W ... werShell-4