Written by Super User.

Get Files' CreationTime, LastWriteTime and FileSize recursively from a folder and export

In the example below, we manually type the folder path. Get-ChildItem cmdlet fetches creation, modification and size of all files under this folder and exports.

$path ="E:\FolderName" 
Get-ChildItem $path -Recurse | select FullName, CreationTime, LastWriteTime, Length | sort CreationTime `
|Export-Csv "C:\Users\myuser\Desktop\FileName.csv" -NoTypeInformation

 

If you have hundreds of folders, you can first import a csv which contains info about folder location and folder name. Then by using a for loop you can make your script to complete the task by itself. In this task I am working on shared folders and I can created a list of shared folders by using Get-SmbShare cmdlet.

Get-SmbShare | select name, path |Export-Csv "C:\smbsharelist.csv" -NoTypeInformation -Encoding UTF8 

 

Your smbsharelist.csv will look like this:

Name,Path
FolderName1,J:\FolderName1
FolderName2,H:\FolderName2
FolderName3,J:\FolderName3
FolderName4,J:\FolderName4
FolderName5,I:\FolderName5

 

The script below imports the csv file first. It will use path information from csv for each path. While exporting, it will use the folder name information and it creates a new csv file for each folder.

Import-Csv -Path "C:\Users\myuser\Desktop\smbsharelist.csv" | ForEach-Object{
$path =$_.Path
$name =$_.Name 
Get-ChildItem $path -Recurse -ErrorAction SilentlyContinue | select FullName, CreationTime, LastWriteTime, Length | sort CreationTime `
|Export-Csv "C:\Users\myuser\Desktop\FS-Shared\$name.csv" -Encoding UTF8 -NoTypeInformation
}

 

I am really thankful to powershell for making my tasks so much easier. I hope you find this post helpful. Thanks for reading.