Get Process From Remote Machine With Process Owner
Hi,
We have about 20 terminal servers running process X and I would like to write a powershell script that goes to the 20 servers(Listed in a notepad file), finds the running process X with the process owner and returns it for every server listed in a notepad
file. There are examples out there but none fit what I need and I have tried to adapt them to my needs but I haven't been successful. Any suggestions would be appreciated.
TIA
September 4th, 2015 11:51am
Sorry, This one will put the server name in the file.
$servers = Get-Content C:\temp\servers.txt
$results = foreach ($server in $servers){
Get-WmiObject win32_process -Filter "name='smc.exe'" | Select-Object @{n='Server';e={$server}},Name,@{n='Owner';e={$_.GetOwner().User}}
}
$results | Out-File C:\temp\process.txt -Append
-
Marked as answer by
Rich Ellis-MC
12 hours 37 minutes ago
-
Unmarked as answer by
Rich Ellis-MC
12 hours 31 minutes ago
-
Marked as answer by
Rich Ellis-MC
12 hours 31 minutes ago
-
Unmarked as answer by
Rich Ellis-MC
12 hours 28 minutes ago
September 4th, 2015 12:50pm
$servers = Get-Content C:\temp\servers.txt
$results = foreach ($server in $servers){
Get-WmiObject win32_process -Filter "name='smc.exe'" | Select-Object Name,@{n='Owner';e={$_.GetOwner().User}}
}
$results | Out-File C:\temp\process.txt -Append
Replace the filter with the name of your process.
September 4th, 2015 12:51pm
Sorry, This one will put the server name in the file.
$servers = Get-Content C:\temp\servers.txt
$results = foreach ($server in $servers){
Get-WmiObject win32_process -Filter "name='smc.exe'" | Select-Object @{n='Server';e={$server}},Name,@{n='Owner';e={$_.GetOwner().User}}
}
$results | Out-File C:\temp\process.txt -Append
-
Marked as answer by
Rich Ellis-MC
12 hours 28 minutes ago
-
Unmarked as answer by
Rich Ellis-MC
12 hours 21 minutes ago
-
Marked as answer by
Rich Ellis-MC
12 hours 21 minutes ago
-
Unmarked as answer by
Rich Ellis-MC
12 hours 18 minutes ago
September 4th, 2015 12:56pm
Thanks for responding. Your script will return any process that a local user is using but none from any terminal services sessions. Any ideas why?
TIA
-
Edited by
Rich Ellis-MC
12 hours 26 minutes ago
September 4th, 2015 2:36pm
Thanks for responding. Your script will return any process that a local user is using but none from any terminal services sessions. Any ideas why?
TIA
-
Edited by
Rich Ellis-MC
12 hours 17 minutes ago
September 4th, 2015 2:41pm
Sorry, This one will put the server name in the file.
$servers = Get-Content C:\temp\servers.txt
$results = foreach ($server in $servers){
Get-WmiObject win32_process -Filter "name='smc.exe'" | Select-Object @{n='Server';e={$server}},Name,@{n='Owner';e={$_.GetOwner().User}}
}
$results | Out-File C:\temp\process.txt -Append
-
Marked as answer by
Rich Ellis-MC
Friday, September 04, 2015 6:34 PM
-
Unmarked as answer by
Rich Ellis-MC
Friday, September 04, 2015 6:40 PM
-
Marked as answer by
Rich Ellis-MC
Friday, September 04, 2015 6:41 PM
-
Unmarked as answer by
Rich Ellis-MC
Friday, September 04, 2015 6:43 PM
September 4th, 2015 4:50pm
Thanks for responding. Your script will return any process that a local user is using but none from any terminal services sessions. Any ideas why?
TIA
-
Edited by
Rich Ellis-MC
Friday, September 04, 2015 6:45 PM
September 4th, 2015 6:35pm
Thanks for responding. Your script will return any process that a local user is using but none from any terminal services sessions. Any ideas why?
TIA
Is it being run from an application server and not locally?
Get-Process cannot see remote apps.
September 4th, 2015 8:02pm
You can use PowerShell Remoting to accomplish this. However, you would need to enable PowerShell Remoting on all of the Terminal Servers. You can then run the script above provided in either a .PS1 file or in a scriptblock like the one below. This is like
executing the .PS1 script locally on the remote machines using the Invoke-Command cmdlet
$servers = Get-Content C:\temp\servers.txt
$results = foreach ($server in $servers)
{
Invoke-Command -FilePath c:\temp\test.ps1 -ComputerName $server
}
$results | Out-File C:\temp\process.txt -Append
September 4th, 2015 9:12pm