Monday, May 11, 2020
PowerShell File List to CSV
If you are looking at how to output specific file information to CSV, like File Extension or the Folder the file is in, you can use IO.FileInfo and IO.DirectoryInfo in PowerShell to achieve a specific result.
$parentFolder = "MyFolder"
$folder = "C:\Temp\" + $parentFolder
$files = Get-ChildItem -Path $folder -Recurse
foreach ($file in $files)
{
$name = ([IO.FileInfo] $file.FullName).Name
$parent = ([IO.DirectoryInfo] $file.FullName).Parent
$extension = ([IO.FileInfo] $file.FullName).Extension
$csvLine = """$parentFolder"",""$parent"",""$name"",""$extension"",""$directoryName"""
$outputFile = "C:\Temp\" + $parentFolder + ".csv"
if ($extension -ne ""){
Add-Content $outputFile $csvLine
}
}
Subscribe to:
Posts (Atom)
Check This Out!
More Links to Good Information
- December (1)
- October (1)
- January (1)
- September (1)
- February (2)
- January (2)
- May (3)
- February (1)
- May (1)
- October (1)
- January (1)
- August (1)
- March (1)
- May (1)
- March (1)
- January (1)
- March (1)
- December (2)
- September (2)
- June (1)
- February (1)
- January (1)
- October (1)
- December (2)
- November (1)
- August (4)
- July (14)
- June (10)
- May (9)
- April (2)
- February (4)
- January (2)
- December (7)
- October (10)