Forum Discussion
I'm stuck on CSV generation based on a list of folders
- Sep 02, 2022
Hey, Kev.
Here's a simpler version for producing the first screenshot. Since it's not creating potentially large variables, it'll scale out significantly better, too.
Get-ChildItem -Directory -Path "D:\Data" | ForEach-Object { $Directory = $_; Get-ChildItem -File -Path ($Directory.FullName) -Filter "*.pst" -Recurse | ForEach-Object { [PSCustomObject] @{ Contoso = $Directory.Name.Replace(" ", "."); FullName = $_.FullName; Name = $_.Name; SizeKB = [math]::Round(($_.Length / 1024), 2); SizeMB = [math]::Round(($_.Length / 1048576), 2); } } } | Export-Csv -NoTypeInformation -Path "D:\Data\someExportFilename.csv";
Cheers,
Lain
Edited: To place a .Replace() on line 8, as I didn't initially spot the slight difference between username and directory name (i.e. the period between given and surnames.)
Edited #2: Added in the Export-Csv command.
Hey, Kev.
Here's a simpler version for producing the first screenshot. Since it's not creating potentially large variables, it'll scale out significantly better, too.
Get-ChildItem -Directory -Path "D:\Data" |
ForEach-Object {
$Directory = $_;
Get-ChildItem -File -Path ($Directory.FullName) -Filter "*.pst" -Recurse |
ForEach-Object {
[PSCustomObject] @{
Contoso = $Directory.Name.Replace(" ", ".");
FullName = $_.FullName;
Name = $_.Name;
SizeKB = [math]::Round(($_.Length / 1024), 2);
SizeMB = [math]::Round(($_.Length / 1048576), 2);
}
}
} | Export-Csv -NoTypeInformation -Path "D:\Data\someExportFilename.csv";
Cheers,
Lain
Edited: To place a .Replace() on line 8, as I didn't initially spot the slight difference between username and directory name (i.e. the period between given and surnames.)
Edited #2: Added in the Export-Csv command.
- Curious_Kevin16Sep 02, 2022Iron ContributorLainRobertson
Thank you so much for quick turnaround ! really appreciate it. If you could update this very same code for export to CSV piece that'd be fantastic !
Thank you again Lain- LainRobertsonSep 02, 2022Silver Contributor
- Curious_Kevin16Sep 02, 2022Iron ContributorLainRobertson
Somehow It slipped from my mind that I was referring to that CSV because it also had some fields that I needed to retain in the output 😞
i.e. - EmailAddress (email address removed for privacy reasons) , ArchiveStatus (Active/Inactive)