edm365f31
 New Member Posts:38

 |
| 03 Nov 2008 06:38 PM |
|
I am trying to use get-process on remote machine
get-process -name winword -computername alt701
How do I make the get-process on remote just for a specific process.
thanks
|
|
|
|
|
bsonposh
 Basic Member Posts:392

 |
| 03 Nov 2008 06:55 PM |
|
Unless you are using the v2 CTP this will not work. You need to use .NET class directly [system.Diagnostics.Process]::GetProcessesByName($processName,$Computer) |
|
Brandon Shell ---------------- Microsoft Powershell MVP https://mvp.support.microsoft.com/profile/Brandon Blog: http://www.bsonposh.com |
|
|
edm365f31
 New Member Posts:38

 |
| 04 Nov 2008 06:16 PM |
|
I am using V2 CTP2 I can easily get rmote process with wmi but wants to use get-process on remote box for specific process. I can do this.. get-process -comp altf21 | where {$_.name -like "svchost*"} or get-process -comp altf21 | where {$_.name -like "svchost*" -or $_.name -like "wmiprvse*"} Is there a way for me to kill or terminate a specific process doing this, also get the owner of a remote process. I appreciate any help on this regards The way I'm getting owner of process right is below and its seems to choke..I ran this scrip on 600 W2k3 boxes. $Rv = gwmi win32_process -filter "name='rvd.exe'" -comp $strComputer if ($rv.name -ne $null) { $c.Cells.Item($intRow,2) = $Rv.name $c.Cells.Item($intRow,3) = $Rv.ProcessID $c.Cells.Item($intRow,4) = (($Rv).getowner()).user $c.Cells.Item($intRow,5) = $Rv.ExecutablePath $c.Cells.Item($intRow,6) = $Rv.ConvertToDateTime($Rv.CreationDate) $intRow = $intRow + 1 } |
|
|
|
|
Shay
 Basic Member Posts:271

 |
| 04 Nov 2008 08:39 PM |
|
You can't kill remote processes using get-process, it is not supported for remote machines (and don't blame PS for it, that's the behavior of the underlying .NET class). However, you can terminate them with WMI: $Rv = gwmi win32_process -filter "name='rvd.exe'" -comp $strComputer if ($rv) { $c.Cells.Item($intRow,2) = $Rv.name $c.Cells.Item($intRow,3) = $Rv.ProcessID $c.Cells.Item($intRow,4) = (($Rv).getowner()).user $c.Cells.Item($intRow,5) = $Rv.ExecutablePath $c.Cells.Item($intRow,6) = $Rv.ConvertToDateTime($Rv.CreationDate) $intRow = $intRow + 1 $Rv.terminate() } Keep in mind thate $Rv can be a collection of processes and the code wan't work unless you pipe it to foreach-object. |
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
edm365f31
 New Member Posts:38

 |
| 05 Nov 2008 04:17 PM |
|
Shay Is there a better way to user of a remote process..this line..**(($Rv).getowner()).user **chokes, hangs, and sits before it continue on. I have to baby-sit the script by restarting winmgmt or killing the wmiprvse.exe to push the script to contnue. Any ideas will be greatly appreciated. We are deploying winrrm on all boxes still trying to do research on that to avoid calling wmi from remote. Thnx for your help Edm |
|
|
|
|
Shay
 Basic Member Posts:271

 |
| 05 Nov 2008 05:02 PM |
|
I can't think of another method right now. So basically you get the processes but when you try to get the owner then it hangs, am i right? |
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
edm365f31
 New Member Posts:38

 |
| 05 Nov 2008 05:41 PM |
|
Yes, I am trying this one... and it allow the script to continue on and just skip Owner for the boxes having wmi problems....but I want to know if i can insert this as a trap??? not really sure how to do this where when it hangs it will trap and then run the get service stop winmgmt...you might have ideas where I can insert the trap $Rv = gwmi win32_process -filter "name='rvd.exe'" -comp $strComputer # if ($rv.name -ne $null) changed 10-03-08 if ($Rv){ $c.Cells.Item($intRow,2) = $Rv.name $c.Cells.Item($intRow,3) = $Rv.ProcessID (Get-Service -comp $strComputer |where {$_.servicename -eq "winmgmt"}).stop() #Start-Sleep -seconds 1 $c.Cells.Item($intRow,4) = ($Rv.getowner()).user $c.Cells.Item($intRow,5) = $Rv.ExecutablePath $c.Cells.Item($intRow,6) = $Rv.ConvertToDateTime($Rv.CreationDate) $intRow = $intRow + 1 } Else { $c.Cells.Item($intRow,1) = $strComputer $c.Cells.Item($intRow,2) = "No Rvd Process" $intRow = $intRow + 1 } |
|
|
|
|
Shay
 Basic Member Posts:271

 |
| 05 Nov 2008 08:52 PM |
|
If no error is raised then trap won't work. I wonder, doe's it also hang when you call getowner() locally on a hanged machine: PS > gwmi win32_process | foreach {$_.getOwner().user} |
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
edm365f31
 New Member Posts:38

 |
| 14 Nov 2008 02:29 PM |
|
Shay - Not able to get back on you on thiis right away but will test this theory we are just in the process of pushing Powershell V2 CTP2 to all our W2K3 boxes. Have you ever played with WinRM? |
|
|
|
|
Shay
 Basic Member Posts:271

 |
| 14 Nov 2008 02:55 PM |
|
V2 is not even at its BETA phase, I recommend not to installing it on production machines. |
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
edm365f31
 New Member Posts:38

 |
| 14 Nov 2008 07:46 PM |
|
Its the only one that has remoting capabilities, more cmdlets, winrm...we are in the process of using opsware. I also have intsallled this in couple of w2k3 box that collects a lot if data from about 700 w2ks boxes with no problems. |
|
|
|
|