Reputation: 100
I have folder and there are sub folders in it. I need file name and size in the csv for all the files in the folder.
Upvotes: 3
Views: 8518
Reputation: 378
This code should work for you
$Directory = "C:\path to directory"
Get-ChildItem -Path $Directory -Recurse -Force | ForEach {
[PSCustomObject]@{
Name = $_.Name
Size = "$([int]($_.length / 1mb)) MB"
}
} | Export-Csv -Path "./temp.csv" -NoTypeInformation
Upvotes: 6