Kill Process On List Of remote Workgroup Servers

1

I have a list of 5 Servers and for specific reasons they are not on the domain. The credentials among them are the same.

I am trying to remotely kill any instance of a process on the machines. For this website I have change the process to notepad.exe

I am having issues trying to determine how to successfully connect to these boxes.

I am running

$StartCheck = Get-WmiObject Win32_Process -Computer $Servers |
  Where-Object { $ProcessNames -contains $_.Name }
$StartCheck | FT * -a;$StartCheck | FT * -a | out-file -FilePath $logfile -Append

and Here.

(Get-WmiObject Win32_Process -Computer $Servers |
  Where-Object { $ProcessNames -contains $_.Name }).Terminate() | out-null

I am faced with the following error

Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005
(E_ACCESSDENIED))
At C:\Users\first.last\Desktop\Kill All Traffic Managers.PS1:67 char:13
+ $EndCheck = Get-WmiObject Win32_Process -Computer $Servers |
+   

What is the easiest way to enter the credentials?

powershell
wmi
credentials
remote-server
get-wmiobject
asked on Stack Overflow May 25, 2018 by Cleadus Fetus

1 Answer

1

Add this to your script and change usernname and P@ssw0rd

$account = "username"
$PASSWORD = ConvertTo-SecureString P@ssw0rd -AsPlainText -Force
$UNPASSWORD = New-Object System.Management.Automation.PsCredential $account, $PASSWORD

Also change your

Get-WmiObject Win32_Process -Computer $Servers`

for

Get-WmiObject Win32_Process -Computer $Servers -Credential $UNPASSWORD
answered on Stack Overflow May 25, 2018 by Frédéric Bonneau • edited Jun 11, 2018 by Frédéric Bonneau

User contributions licensed under CC BY-SA 3.0