Return File information from a directory

I have the following Script . How can I call the computer name from a text file. I would like to check each computer that is listed in a file located at c:\ActiveComputers.txt for this file and return the file information

$items = Get-ChildItem -Path "\\COMPUTERNAME \c$\Temp\bin\hs_err_pid*.log"

foreach ($item in $items)
      if ($item.Attributes -ne "Directory")
            Write-Host $item.Fullname $item.CreationTime
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:
Hey :)

Combine Get-Content with either ForEach (as you have done before) or ForEach-Object (%, as below).

I've also changed the If statement into Where-Object (?). You can determine if something is a directory (or not in this case) using the statement below.

And I switched Write-Host for Select-Object, much greater flexibility in the output. From Format-Table, to Export-CSV, to Out-GridView, and rather a lot more.

Get-Content "SomeFile.txt" | %{
  Get-ChildItem -Path "\\$_\c$\Temp\bin\hs_err_pid*.log" | 
    ?{ !$_.PsIsContainer } | Select-Object FullName, CreationTime

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jfgrayAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.