Powershell find file question

fertigj
fertigj used Ask the Experts™
on
Hello..

I am running into an issue that I believe could be solved with a fairly simple script.    I could easily write this is vbs but it seems like as good as any  
time to start playing with powershell :)

Ok... in the end I would like to have a script that can
   - Read a list of computers names from a txt file
      -loop through each computer name
         -ping printer to see if it is online
           -search the base drive for a specific file \\somecomputer\c$\somefile.txt   {recursively through all folders}
            -if file exists copy the contents to a local file  {results.txt}

If you know of any scripts that are close to this that would be very helpful.   It not piece part scripts that do this would work just as well.
Thanks for any information.

   
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kent DyerIT Security Analyst Senior

Commented:
I know this does not exactly answer your question, but gets you started down the right path..

http://www.computerperformance.co.uk/ezine/ezine133.htm

HTH,

Kent
PowerShell Developer
Top Expert 2010
Commented:
Hello there :)

See below.

Chris
# Read a list of computers names from a txt file.
# NOTE: You may also consider Import-Csv depending on the nature
# of the input file
# loop through each computer name
Get-Content "TheFile.txt" | ForEach-Object {

  # ping printer to see if it is online
  # Test-Connection is WMI Ping, and $_ is the current computer,
  # the current object in the pipeline
  If (Test-Connection $_ -Count 1 -Quiet) {

    # This is the slow bit
    # search the base drive for a specific file
    # \\somecomputer\c$\somefile.txt   {recursively through all folders}
    # ForEach-Object, just in case you have more than one match
    Get-ChildItem "\\$_\c$" -Filter "somefile.txt" -Recurse | 
      ForEach-Object {

        # if file exists copy the contents to a local file  {results.txt}
        Get-Content $_.FullName | Add-Content "results.txt"

      # End of files loop
      }

  # End of If for Ping
  }

# End of computer loop
}

Open in new window

Author

Commented:
Didn't mean to say it needed to be a completed script....but exactly what I was looking for :)   Thanks much!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial