Forum Discussion
Maher Ramadan
Jan 22, 2022Brass Contributor
only | Export-csv is having an issue exporting the data, the rest of the PS works fine
i run the below against a CSV file and works fine on exchange online PS, foreach($m in $mailboxes) {Get-MailboxStatistics $m.Identity.ToString() |select Identity, displayname, LastLogonTime, itemcou...
- Jan 23, 2022The append didn’t work for me guess it is used to add more than one get- to the same file
However the other approach extracting the results then exporting them worked just fine, thank you
$Results = foreach($m in $mailboxes) {Get-MailboxStatistics $m.Identity.ToString() |select Identity, displayname, LastLogonTime, itemcount, totalitemsize; Start-Sleep -Milliseconds 500}
$Results | Export-CSV -Path " D:\123.csv" -NoTypeInformation
VasilMichev
MVP
Since you are running Export-CSV inside the foreach loop, the file gets overwritten at each iteration, that's expected. Either move the Export-CSV cmdlet outside of the loop, or use the -Append switch to "add" to the file, instead of overwriting it.
Maher Ramadan
Jan 23, 2022Brass Contributor
The append didn’t work for me guess it is used to add more than one get- to the same file
However the other approach extracting the results then exporting them worked just fine, thank you
$Results = foreach($m in $mailboxes) {Get-MailboxStatistics $m.Identity.ToString() |select Identity, displayname, LastLogonTime, itemcount, totalitemsize; Start-Sleep -Milliseconds 500}
$Results | Export-CSV -Path " D:\123.csv" -NoTypeInformation
However the other approach extracting the results then exporting them worked just fine, thank you
$Results = foreach($m in $mailboxes) {Get-MailboxStatistics $m.Identity.ToString() |select Identity, displayname, LastLogonTime, itemcount, totalitemsize; Start-Sleep -Milliseconds 500}
$Results | Export-CSV -Path " D:\123.csv" -NoTypeInformation
- Maher RamadanJan 23, 2022Brass Contributorthis way the results are exported then written to the file, hope it helps someone as poor as i am in scripting 🙂