# Need Help with PowerShell Script

Greeting Experts,

I need help creating PowerShell script to read the name multiple files (over 2,000 files names) in a file directory and then import that information into a ".csv" document. Can somebody help me with this task...
###### Who is Participating?

Commented:
There is no need for intermediate variables, especially when it comes to large file structures. It's far less resource intensive to let the pipeline do the work.
In line 2, select the properties you want exported, in the order in which you want them to appear as columns in the csv.
Start with a smaller folder until you're sure you have identified all the properties before going for the big one.
To see all the available properties, just enter
Get-Item S:\ome\file.ext | Select *
If you're only interested in certain file types, change the Filter argument accordingly; this is the fastest way, because items not matching won't reach the pipeline.
For more than one pattern, you can use the -Include (or -Exclude) argument (works only in conjunction with -Recurse!), as in
Get-ChildItem -Path C:\Source -Include *.doc?, *.xls?,
The files can be filtered in the pipeline as well for more complex patterns/properties (like age), but that'll be slower than using -Filter.
Get-ChildItem -Path C:\Source -Filter *.* -Recurse -File |
Select-Object -Property Name, DirectoryName, LastWriteTime |
Export-Csv -NoTypeInformation -Path C:\Temp\FileList.csv

Or as a one-liner:
Get-ChildItem -Path C:\Source -Filter *.* -Recurse -File | Select-Object -Property Name, DirectoryName, LastWriteTime | Export-Csv -NoTypeInformation -Path C:\Temp\FileList.csv

0

CEO J0rt3g4 Consulting ServicesCommented:
Maybe if you could put an example of the dummy text information it could be more helpful for the end result.

$FolderPath="C:\file\path\ThisFolder"$FolderPath = "D:\Cloud\OneDrive\Desktop Diciembre 2017\ee\text\files"
$outputfileName= "Output.csv"$files=[System.IO.Directory]::GetFiles($FolderPath)$AllFilesInfo=@()
if($files.Count -gt 0){ foreach($file in $files){$content = Get-Content $file$AllFilesInfo+= $content }$AllFilesInfo | Export-Csv -NoTypeInformation -Path "$FolderPath\\$outputfileName"
}
else{
Write-Warning "There are no files in that Folderpath:""$FolderPath""" }  0 OwnerCommented: function Get-Files { <# .SYNOPSIS Gets list of filenames from a source directory and all subdirectories and exports to a csv file .EXAMPLE Get-Files -FolderPath c:\temp -OutputFileName output.csv #> [CmdletBinding()] param ( [Parameter(Mandatory=$false, Position=0)]
[System.String] $FolderPath = "C:\file\path\ThisFolder", [Parameter(Mandatory=$true, Position=1)]
[String]$outputfileName= "Output.csv" )$AllFilesInfo = @()
$files=Get-ChildItem -Path$FolderPath -Recurse

if($files.Count -gt 0){ foreach($file in $files){$FileInfo=New-Object -TypeName PSObject
Add-Member -InputObject $FileInfo -MemberType NoteProperty "Filename" -Value$file.fullname

$AllFilesInfo +=$FileInfo
}
$AllFilesInfo | Export-Csv -NoTypeInformation -Path "$FolderPath\\$outputfileName" } else{ Write-Warning "There are no files in that Folderpath:""$FolderPath"""
}
}

0

Batchelor, Developer and EE Topic AdvisorCommented:
Do you need to go thru subfolders too? Do you only need file names or more info?
0

SecurityAuthor Commented:
I will be scanning a large file directory with subfolders ( 10,500 files) that go for about 10 layers.
0

Batchelor, Developer and EE Topic AdvisorCommented:
And what should your "CSV" look like? Note that a CSV is only a CSV if it has more than one column, otherwise it is just a text file ;-).
Whatsoever, the simplest approach is
Get-ChildItem C:\Temp\EE\files -recurse -Name | Out-File C:\Temp\EE\result.txt

1

SecurityAuthor Commented:
It is going to be differnt types of files...docs, xlsx, pdf, and other ext .  I just want to get the name of the file and import it over to the .csv file
0

Commented:
1) Do you really just the file name only, or the full path including the directory?
If you really want the file name only:
2a) Have you considered what you're going to do with duplicate file names, which is in the realm of the possible? You'll have no way to identify where the duplicate names were coming from.
2b) Do you really want a csv (with a header line of a single column name) or just a plain text file?
If you want the full file path including the directory:
2) Do you still want the files as one single path (one single column in a csv), or rather two separate columns (file name and directory name)?

3) Do you want all files under the root folder, or a filtered subset?
If a filtered subset only:
4a) Do you want a whitelist (return only file names matching a list of extensions) or a blacklist (return all files except for those matching a list of extensions)?
4b) What is the list of file extensions?
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.