none
Powershell Export to csv or text file RRS feed

  • Question

  • Hi All,

    I am querying AD to get the group details and I want to output to be in the below format. Is it possible via powershell?

    NAME Members AD STATUS
    Group 1 Member 1 Active
      Member 2 Inactive
      Member3 Active
    Group 2 Member 1 Active
      Member 2 Active
    Group 3 Member 1 Active

    Kindly assist. Thanks.


    Rajesh

    Tuesday, April 9, 2019 4:27 PM

All replies

  • You can try this command 

    Get-ADGroupMember -Identity "Enterprise Admins"
     -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled } | Export-Csv C:\ADResuts.csv


    This will display the members of Enterprise Admins group 

    like wise you can modify the command according to your need.

    Regards,

    Ramabadran Vasudevan

    Please don't forget to mark Propose as answer, to help others who have the same issue.

    Tuesday, April 9, 2019 4:38 PM
  • Please try this as well

    Get-ADGroup -filter "Groupcategory -eq 'Security' -AND GroupScope -ne 'DomainLocal' -AND Member -like '*'" -Properties Member |
    foreach { 
     Write-Host "Exporting $($_.name)" -ForegroundColor Cyan
     $name = $_.name -replace " ","-"
     $file = Join-Path -path "C:\work2" -ChildPath "$name.csv"
     $_.member | Get-ADObject -Properties SamAccountname,Title,Department |
     Select Name,SamAccountName,Title,Department,DistinguishedName,ObjectClass |
     Export-Csv -Path $file -NoTypeInformation
    }

    Regards,

    Ramabadran Vasudevan

    Please don't forget to mark Propose as answer, to help others who have the same issue.

    Tuesday, April 9, 2019 4:43 PM
  • Hi 

    If you want to export members of multiple AD groups you can use the below script

    $groups = Get-Content C:\Temp\grouplist.txt
    
    $results = foreach ($group in $groups) {
        Get-ADGroupMember $group | select samaccountname, name, @{n='GroupName';e={$group}}, @{n='Description';e={(Get-ADGroup $group -Properties description).description}}
    }
    
    $results
    
    $results | Export-csv C:\Temp\grouplistresult.csv -NoTypeInformation

    In the above script it reads the input from  "C:\Temp\\grouplist.txt" which is having the group list where you want to see the members 

    and the reports will be exported to C:\Temp\grouplistresult.csv format

    Regards,

    Ramabadran Vasudevan

    Please don't forget to mark Propose as answer, to help others who have the same issue.

    Tuesday, April 9, 2019 4:53 PM
  • Hi 

    If you want to export members of multiple AD groups you can use the below script

    $groups = Get-Content C:\Temp\grouplist.txt
    
    $results = foreach ($group in $groups) {
        Get-ADGroupMember $group | select samaccountname, name, @{n='GroupName';e={$group}}, @{n='Description';e={(Get-ADGroup $group -Properties description).description}}
    }
    
    $results
    
    $results | Export-csv C:\Temp\grouplistresult.csv -NoTypeInformation

    In the above script it reads the input from  "C:\Temp\\grouplist.txt" which is having the group list where you want to see the members 

    and the reports will be exported to C:\Temp\grouplistresult.csv format

    Regards,

    Ramabadran Vasudevan

    Please don't forget to mark Propose as answer, to help others who have the same issue.

    None of your answers actually answer the question.  The request is for a specific format.


    \_(ツ)_/

    Thursday, April 11, 2019 4:50 PM
    Moderator
  • Hi All,

    I am querying AD to get the group details and I want to output to be in the below format. Is it possible via powershell?

    NAME Members AD STATUS
    Group 1 Member 1 Active
      Member 2 Inactive
      Member3 Active
    Group 2 Member 1 Active
      Member 2 Active
    Group 3 Member 1 Active

    Kindly assist. Thanks.


    Rajesh

    There is not CmdLet that will produce this exact format.  You can use Format-Table to get close by using the "group" option.

    Get-Process | Format-Table -Group Name  -HideTableHeaders


    \_(ツ)_/

    Thursday, April 11, 2019 4:52 PM
    Moderator
  • Yes ,I agree but just gave some insights so that any one of my codes will be useful .

    Also the script which provided can be customized based on his need.

    Let me work towards it and share it once again as per the requirement.

    Regards,

    Ramabadran Vasudevan

    Please don't forget to mark Propose as answer, to help others who have the same issue.

    Thursday, April 11, 2019 6:28 PM
  • Please understand that this is nt a free script writing forum.  Users asking for others to write custom scripts is not supported her.

    If you just need the exercise then go ahead but we try to discourage users from asking for custom code and consulting outside of answering specific technical questions.


    \_(ツ)_/

    Thursday, April 11, 2019 6:34 PM
    Moderator
  • Thanks for pointing right directions.

    Regards,

    Ramabadran Vasudevan

    Please don't forget to mark Propose as answer, to help others who have the same issue.

    Thursday, April 11, 2019 7:08 PM
  • Hi Rajesh,

    Thanks for your query  and reaching us!

    If you have any script requirements you check this repository where we have bundles of scripts which aids your need or else you can submit a new script requirement there someone will get back to you.

    Link to URL :  https://gallery.technet.microsoft.com/scriptcenter/

    Regards,

    Ramabadran Vasudevan

    Please don't forget to mark Propose as answer, to help others who have the same issue.


    Thursday, April 11, 2019 7:17 PM
  • Yes.  The script request forum is here: Forum for Script requests

    Also the script requested is not trivial.  It is a very good learning exercise for anyone wanting to learn technical programming skills.  It can be done by designing a custom formatter CmdLet or by just writing a good "ForEach-Object" loop.


    \_(ツ)_/

    Thursday, April 11, 2019 7:22 PM
    Moderator