none
Powershell - Simple ping and query

    Question

  • Hi guys,

    Im trying to write an ps script that will simply ping all pc's within domain , and check if a process is running on them.

    Currently i have a script that pings and exports names of pc's and thier ip's; 

     http://www.youdidwhatwithtsql.com/ping-all-domain-computers-with-powershell/209#ixzz1kQG467Td      into excel  respective .xls files...

     

    What i would like, to is is check the alive pc's and see if they are running a specified prices , i was hoping to use something like;

     

    Get-Process xxxxxxxxx > output.txt       to search for the application and then export user and pc details to a final report.

     

    OR to create a filter where only pc's and Ip's where the process (and its respective details, pid and uptime) is running are writen to a file / report.

     

    If anyone can help or has ideas, please reply and if appropriate i would be happy to offer reward.

    thanks,

     

    Rob from Sydney

     


    Tuesday, January 24, 2012 11:52 PM

Answers

  • This script should suit for what you requested.  You can modify it further for anything else required.
    $Proc = "MyProc.exe"
    $PCs = get-content pclist.txt
    $Output = ProcStatus.txt
    "$(Get-Date) - Checking for status of $Proc" | Out-File $Output
    
    foreach ($PC in $PCs){
    "Processing $PC"
      if (test-connection $PC -Quiet -Count 1){
        if (Get-Process $Proc -ComputerName $PC){
          "$Proc is running on $PC" | Out-File $Output -Append
        } else {
          "$Proc is not running on $PC" | Out-File $Output -Append
        }
      } else {
      "Could not contact $PC" | Out-File $Output -Append
      }


    Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP

    Engineering Efficiency
    @Rich_Prescott
    Windows System Administration tool
    AD User Creation tool

    Sunday, February 19, 2012 8:45 PM

All replies

  • Your question  is too vague.  What specifically are you having trouble with.

    YOu did not write the script you linked in here. It has nothing to do with gettingprocesses..

    Type help get-process -full to see how to use get-process.

    It is completely unclear what you mean by creating a filter?  To filter what?

     


    jv
    Wednesday, January 25, 2012 12:07 AM
  • Basically,

    I dont know how to use the get-process command, so that i can read an excel file, with computer name and ip data , and check weather the pc from list is running an specified process.

    The output from the ping script  (above) , writes the results in excel sheet , vaules $computer,$ipAddress , starting in A1 and B1

    It is completely unclear what you mean by creating a filter?  To filter what?    -- i was wondering if the process check could be combined into the ping all script so that only the pc/ips with the specified process are recorded to output.

    thanks,

     

    Igor

    Wednesday, January 25, 2012 12:20 AM
  • There are many examples of using Excel files for input and output in the script repository.

     


    jv
    Wednesday, January 25, 2012 12:30 AM
  • This script should suit for what you requested.  You can modify it further for anything else required.
    $Proc = "MyProc.exe"
    $PCs = get-content pclist.txt
    $Output = ProcStatus.txt
    "$(Get-Date) - Checking for status of $Proc" | Out-File $Output
    
    foreach ($PC in $PCs){
    "Processing $PC"
      if (test-connection $PC -Quiet -Count 1){
        if (Get-Process $Proc -ComputerName $PC){
          "$Proc is running on $PC" | Out-File $Output -Append
        } else {
          "$Proc is not running on $PC" | Out-File $Output -Append
        }
      } else {
      "Could not contact $PC" | Out-File $Output -Append
      }


    Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP

    Engineering Efficiency
    @Rich_Prescott
    Windows System Administration tool
    AD User Creation tool

    Sunday, February 19, 2012 8:45 PM