locked
Locate process running in all my servers using powershell RRS feed

  • Question

  •  Hi all !

     Is there a way to find or list if a specific process is runing in all servers in my domain using powershell ? 

     For exemple, I would like to list all server in my domain that is running "abc.exe".

    I was trying something like this

    Thank you



    • Edited by Vitor Retta Thursday, December 13, 2018 4:24 PM
    Thursday, December 13, 2018 4:21 PM

All replies

  • This might work:

    Get-Content c:\temp\ListOfServers.txt | foreach {
        $machine = $_.Trim()
        Get-Process -Name 'abc.exe' -ComputerName $machine
        $machine | Write-Output
    } | sort | Set-Content c:\temp\ServersRunningABC.txt


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)


    Thursday, December 13, 2018 4:37 PM
  • Cannot convert the "subject" value of type "System.String" to typeSystem.Management.Automation.ScriptBlock"

     ps1:5 car:3

    Thursday, December 13, 2018 5:15 PM
  • This might work:

    Get-Content c:\temp\ListOfServers.txt | foreach {
        $machine = $_.Trim()
        Get-Process -Name 'abc.exe' -ComputerName $machine
        $machine | Write-Output
    } sort | Set-Content c:\temp\ServersRunningABC.txt


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Missing a pipe.


    \_(ツ)_/

    Thursday, December 13, 2018 6:43 PM
  • I corrected the code in my original post. It was missing a "|" after the ForEach" block.

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Thursday, December 13, 2018 7:05 PM
  • Oops. Fixed the code in the post.

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Thursday, December 13, 2018 7:06 PM
  •     $MyServerList=Get-Content C:\Temp\MyServers.txt
    
    
       $MyCommand={
    
    
        Try{
    
             $MyService= Get-Service -Name "Windows Update" -ErrorAction Stop | Select -ExpandProperty Name 
             Return "$Env:Computername,Service Found:$MyService"
    
            }Catch{
    
            Return "$Env:Computername,Service $MyService Not Found"
    
            }
       }
         
      
         
      Invoke-Command  $MyServerList -scriptblock $MyCommand

    • Proposed as answer by ComputerScott Thursday, December 13, 2018 11:20 PM
    Thursday, December 13, 2018 11:19 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Monday, December 24, 2018 3:13 AM