PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,328 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello everyone, I have been tasked to create an automatic report that will be emailed as csv each day, showing sizes of folders on a particular server. I have googled and slightly modified following cmdlet:
Get-ChildItem "<path to folder>" | Where-Object { $.PSIsContainer } | ForEach-Object { $.FullName + " -- " + [Math]::Round((Get-ChildItem $_.FullName -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB, 2) + " MB" }
But, when I pipe the result to Export-Csv (with specified path and delimiter), I get only this in the csv file:
Can you please help me to create a csv from this? Out file works fine, but this way I am not able to delimit the values. Thank you very much, Tomas
How about this.
Get-ChildItem "C:\temp" | Where-Object { $_.PSIsContainer } | ForEach-Object {
[PSCustomObject]@{
'Name' = $_.FullName;
'MB' = [Math]::Round((Get-ChildItem $_.FullName -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB, 2)
}
} | Export-Csv -Path "c:\temp\report.csv" -NoTypeInformation
Get-Content "c:\temp\report.csv"