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
                  
           
      }
}
jfgrayAsked:
Who is Participating?
 
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.

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

Open in new window

0
 
jfgrayAuthor Commented:
THANK YOU ! ! !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.