Hi @Nancy J ,
the issue why your script is not working ist this:
This script below works here. I just modified the path and removed the | Select Name
in line 6. Also make sure the folders records
and 2022-04
exists in file system.
#Variables
$rootfolder = "C:\Junk"
$csvpath = "C:\Junk\records\2022-04"
#Get folder names and generate lists of files in each
$folder = Get-ChildItem -Path $rootfolder -Depth 0 -Directory
foreach ($Name in $folder) {
$Name
$folderpath = "$rootfolder\$Name"
$csvfilename = "$csvpath\$Name.csv"
Get-ChildItem -Path $folderpath -Recurse -Force -ErrorAction SilentlyContinue |
Select-Object Directory, Name, CreationTime, LastWriteTime |
Export-Csv $csvfilename -NoTypeInformation
}
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten