Share via

Powershell commands on multiple windows

António 1 Reputation point
2022-02-26T21:46:02.897+00:00

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

Windows for business | Windows Server | User experience | PowerShell

1 answer

Sort by: Most helpful
  1. Carlos Solís Salazar 18,376 Reputation points MVP
    2022-02-26T22:02:06.73+00:00

    First try to get the script to work locally, then replicate it on your remote command

    This could be an example of the local command:

    $PIDS = Get-Content C:\PIDs.txt
    ForEach ($PID in $PIDS) {
    Write-Output $PID
    }

    Was this answer helpful?

    0 comments No comments

Your answer

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