V
V
Vertizo2021-02-09 10:24:44
PowerShell
Vertizo, 2021-02-09 10:24:44

Remote process termination on a group of servers via Powershell?

We need a script that will kill two processes on a certain group of servers. I got the following look:

$servers = @('srv-1','srv-2','srv-3')
Get-WmiObject Win32_Process -Filter "ExecutablePath LIKE '%process%'" `
 -ComputerName $servers | Invoke-WmiMethod -Name Terminate

It works like this.

But ideally, I need to take information from AD, throw the following type, but give a multiple error
- Get-WmiObject : Сервер RPC недоступен.
Import-Module ActiveDirectory
$servers = (Get-ADComputer -Filter "Name -like 'srv-*'")
Get-WmiObject Win32_Process -Filter "ExecutablePath LIKE '%process%'" `
 -ComputerName $servers | Invoke-WmiMethod -Name Terminate


What would be the correct syntax in the second case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Dmitriev, 2021-02-09
@Vertizo

Did you even look at the output of $servers in the first and second cases?
In the first you have names, in the second you have arrays.
You need to get server names from $servers in the second case.
For example, using -ComputerName $servers.Name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question