# This script will export all of the information from a directory and all of its subdirectories into a csv file
$workingDir = "c:\Windows\system32"
$outputFile = "c:\temp\list.csv"
function main
{
# Check and make sure the directory exists
if ( Test-Path $workingDir )
{
$filesList = Get-ChildItem -Path $workingDir -Recurse -force | where { ! $_.PSIsContainer }
$headerLine = "Date,FileName"
$content = @()
$content = $content + $headerLine
foreach($file in $filesList)
{
$line = (($file.LastWriteTime).ToString()) + "," + ($file.FullName)
$content = $content + $line
}
$contentResult = Set-Content -Path $outputFile -Value $content -Force
}
else
{
Write-Output "$workingDir path not found."
}
}
main