Powershell Script List all Files Under a Directory


You can  use  this script  to list  all file  under a directory.  Don’t forget to change  ” -Value ‘AYILDIRIMPC,C:\'”  as  you wish.

$Hostname = $env:computername
$path = 'C:\'
$file = 'ListFile.txt'
New-Item -path $path -Name $file -Value 'AYILDIRIMPC,C:\' -ItemType file -force
Get-Content "C:\ListFile.txt"|findstr "$Hostname"|%{ $_.Split(',')[1];} > C:\ListFile2.txt
$InfoServer = Get-Content "C:\ListFile2.txt"
echo "Started" > C:\List_"$Hostname".txt
foreach ($direct in $InfoServer)
{
tree /F /A "$direct" >> C:\List_"$Hostname".txt

 

Tagged In:

I'm a IT Infrastructure and Operations Architect with extensive experience and administration skills and works for Turk Telekom. I provide hardware and software support for the IT Infrastructure and Operations tasks.

205 Total Posts
Follow Me