locked
PS - export results to csv RRS feed

  • Question

  • Hi, my script export all results to TXT file on MS Exchange server 2010 in Powershell. I don't know how to export to CSV file. Plese help me. Thank's Jan

    write-output “” > C:\Scripts\DGmembers.txt
    get-distributiongroup | Sort -Property DisplayName | foreach {
    $name = $_.displayname
    $output = ‘Group Name: ‘ + $Name
    write-output $output >> C:\Scripts\DGmembers.txt
    Get-DistributionGroupMember $name | Sort -Property DisplayName | Select DisplayName, Alias >> C:\Scripts\DGmembers.txt
    write-output “” “” >> C:\Scripts\DGmembers.txt
    }

    Wednesday, July 20, 2016 8:46 AM

Answers

  • Get-Distributiongroup | Foreach {
            $Group = $_.Name
                Get-DistributionGroupMember -Identity $Group | 
                        Select Displayname,Alias,@{Label = 'Group'; Expression = {$Group} }  } | 
                                    Sort Displayname | Export-Csv C:\Test\DistGrp.csv 






    • Edited by Vincent Karunaidas Wednesday, July 20, 2016 9:35 AM
    • Proposed as answer by jrv Wednesday, July 20, 2016 1:30 PM
    • Marked as answer by Richard MuellerMVP Friday, September 2, 2016 6:26 PM
    Wednesday, July 20, 2016 9:35 AM

All replies

  • Get-Distributiongroup | Foreach { 
               Get-DistributionGroupMember -Identity $_  | 
                                  Select Displayname,Alias } |
                                               Sort Displayname | Export-Csv C:\Test\DistGrp.csv
    

    Wednesday, July 20, 2016 9:34 AM
  • Get-Distributiongroup | Foreach {
            $Group = $_.Name
                Get-DistributionGroupMember -Identity $Group | 
                        Select Displayname,Alias,@{Label = 'Group'; Expression = {$Group} }  } | 
                                    Sort Displayname | Export-Csv C:\Test\DistGrp.csv 






    • Edited by Vincent Karunaidas Wednesday, July 20, 2016 9:35 AM
    • Proposed as answer by jrv Wednesday, July 20, 2016 1:30 PM
    • Marked as answer by Richard MuellerMVP Friday, September 2, 2016 6:26 PM
    Wednesday, July 20, 2016 9:35 AM
  • Hi, thank you, but I need separate DisplayName,Alias,Group to columns. And further I need view Czech letters, for example in picture. 

    Thank you.

    Monday, July 25, 2016 1:11 PM
  • You will have to install the correct versions of the language packs and use a correct version of Excel.

    Use " Export-CsvC:\Test\DistGrp.csv  -Delim ';' -Encoding Unicode"


    \_(ツ)_/

    Monday, July 25, 2016 2:45 PM