SOLVED

Exporting inbox rule from mailbox csv list and export result to CSV file

%3CLINGO-SUB%20id%3D%22lingo-sub-1522796%22%20slang%3D%22en-US%22%3EExporting%20inbox%20rule%20from%20mailbox%20csv%20list%20and%20export%20result%20to%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1522796%22%20slang%3D%22en-US%22%3E%3CP%3Etrying%20to%20Export%20inbox%20rule%20from%2050%20mailbox%20csv%20list%20and%20export%20result%20to%20CSV%20file%20but%20the%20resulting%20CSV%20file%20only%20shows%201%20user.%20please%20check%20script%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EImport-Csv%20%22C%3A%5CPS%5CINBOXRULE%5CLIST.CSV%22%20%7C%20foreach%20%7B%20Get-InboxRule%20-mailbox%20%24_.UserPrincipalName%20%7C%20Export-Csv%20-Path%20c%3A%5CPS%5CINBOXRULE%5Cresult.CSV%20%7D%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1522796%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1523900%22%20slang%3D%22en-US%22%3ERe%3A%20Exporting%20inbox%20rule%20from%20mailbox%20csv%20list%20and%20export%20result%20to%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1523900%22%20slang%3D%22en-US%22%3E%3CP%3EYou're%20overwriting%20the%20CSV%20file%20on%20each%20iteration.%20Add%20the%20-Append%20switch%20after%20Export-CSV.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1525452%22%20slang%3D%22en-US%22%3ERe%3A%20Exporting%20inbox%20rule%20from%20mailbox%20csv%20list%20and%20export%20result%20to%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1525452%22%20slang%3D%22en-US%22%3E%3CP%3Ethanks%20-ERR%3AREF-NOT-FOUND-%40Vasil%20Michev%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EImport-Csv%20%22C%3A%5CPS%5CINBOXRULE%5CLIST.CSV%22%20%7C%20foreach%20%7B%20Get-InboxRule%20-mailbox%20%24_.UserPrincipalName%20%7C%20Export-Csv%20-Path%20c%3A%5CPS%5CINBOXRULE%5Cresult.CSV%20-append%7D%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Super Contributor

trying to Export inbox rule from 50 mailbox csv list and export result to CSV file but the resulting CSV file only shows 1 user. please check script:

 

Import-Csv "C:\PS\INBOXRULE\LIST.CSV" | foreach { Get-InboxRule -mailbox $_.UserPrincipalName | Export-Csv -Path c:\PS\INBOXRULE\result.CSV }

2 Replies
Best Response confirmed by Marvin Oco (Super Contributor)
Solution

You're overwriting the CSV file on each iteration. Add the -Append switch after Export-CSV.

thanks @Vasil Michev

 

Import-Csv "C:\PS\INBOXRULE\LIST.CSV" | foreach { Get-InboxRule -mailbox $_.UserPrincipalName | Export-Csv -Path c:\PS\INBOXRULE\result.CSV -append}