locked
AD groups in a csv. RRS feed

  • Question

  • Hi there,

    does anyone can provide me a script to create a CSV. out of from AD via powershell script

    Thursday, July 16, 2015 7:55 AM

Answers

  • Hi Marcus,

    sure thing:

    Get-ADGroup -Filter "*" | Export-Csv groups.csv

    Cheers,
    Fred

    Ps.: You can use Export-Csv on almost any output in Powershell.
    PPs.: Most Get- Commands for AD have the parameter -Property. Using this you can retrieve additional information that may not be shown by default.


    There's no place like 127.0.0.1

    • Proposed as answer by Mike Laughlin Thursday, July 16, 2015 12:01 PM
    • Marked as answer by Elaine Jing Monday, July 20, 2015 9:27 AM
    Thursday, July 16, 2015 8:06 AM
  • Hi Marcus,

    with PowerShell v3+ you do not need to explicitely load it.

    In v2 you can load it with this command:

    Import-Module ActiveDirectory

    Note however, that the module needs to be present on the computer in question (Any Domain Controller 2008 R2 or newer; Any Server with the AD administration tools feature enabled; Any Client with the Remote Server Administration Tools (RSAT) installed).

    You can get a list of all available Module with this command:

    Get-Module -ListAvailable

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Proposed as answer by Mike Laughlin Thursday, July 16, 2015 12:01 PM
    • Marked as answer by Elaine Jing Monday, July 20, 2015 9:27 AM
    Thursday, July 16, 2015 9:00 AM

All replies

  • Hi Marcus,

    sure thing:

    Get-ADGroup -Filter "*" | Export-Csv groups.csv

    Cheers,
    Fred

    Ps.: You can use Export-Csv on almost any output in Powershell.
    PPs.: Most Get- Commands for AD have the parameter -Property. Using this you can retrieve additional information that may not be shown by default.


    There's no place like 127.0.0.1

    • Proposed as answer by Mike Laughlin Thursday, July 16, 2015 12:01 PM
    • Marked as answer by Elaine Jing Monday, July 20, 2015 9:27 AM
    Thursday, July 16, 2015 8:06 AM
  • Thanx fo the quick answer!

    Do I have to set in the AD modul in Powershell.

    Thursday, July 16, 2015 8:36 AM
  • Whats the script for the AD Modul if so?

    Thanx

    Thursday, July 16, 2015 8:38 AM
  • Hi Marcus,

    with PowerShell v3+ you do not need to explicitely load it.

    In v2 you can load it with this command:

    Import-Module ActiveDirectory

    Note however, that the module needs to be present on the computer in question (Any Domain Controller 2008 R2 or newer; Any Server with the AD administration tools feature enabled; Any Client with the Remote Server Administration Tools (RSAT) installed).

    You can get a list of all available Module with this command:

    Get-Module -ListAvailable

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Proposed as answer by Mike Laughlin Thursday, July 16, 2015 12:01 PM
    • Marked as answer by Elaine Jing Monday, July 20, 2015 9:27 AM
    Thursday, July 16, 2015 9:00 AM
  • Get-ADGroup -Filter "*" | Export-Csv groups.csv

    Hi Fred,

    when I have the Group "dedre-dmc-lager" where do I have to set it on the script?

    Monday, July 20, 2015 2:44 PM
  • Here's the documentation for the cmdlet:

    http://ss64.com/ps/get-adgroup.html


    EDIT: The short answer is:

    Get-ADGroup groupname | Export-Csv .\file.csv -NoTypeInformation


    Monday, July 20, 2015 2:47 PM
  • Hi Marcus,

    Mike is totall right (see his edit). However, if you want to see a bit about using filters, then with filters that would be ...

    Get-ADGroup -Filter "name -like 'dedre-dmc-lager'" | Export-Csv groups.csv

    You can use wildcards in filters or filter by a property other than name.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Monday, July 20, 2015 3:17 PM
  • Thank so much guyz,

    but Iam still have no success:

    Tuesday, July 21, 2015 2:43 PM
  • Hi Marcus,

    does it throw an error? If yes, please post the error.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, July 21, 2015 3:07 PM
  • issue error
    Wednesday, July 22, 2015 7:07 AM
  • Hello Fred,

    above thats the error message I'am gonna get.

    The group is, please see screenshot belowgROUP

    Wednesday, July 22, 2015 7:10 AM
  • You do not have access to the file

    \_(ツ)_/

    Wednesday, July 22, 2015 7:13 AM
  • Even with my delegation account?

    Whoch rights do i need

    Wednesday, July 22, 2015 7:35 AM
  • Hi Marcus,

    you confused JRV and my recommendations and combined pieces of both. Try either of these two options:

    # Option 1
    Get-ADGroup "DEDRE-DMS-Lager"
    
    # Option 2
    Get-ADGroup -Filter "name -eq 'DEDRE-DMS-Lager'"

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Wednesday, July 22, 2015 7:42 AM
  • Wednesday, July 22, 2015 8:13 AM
  • i think that worked and now? How do i get it in CSV?
    Wednesday, July 22, 2015 8:14 AM
  • after the command use | export-csv c:\temp\csvfilename.csv (use pipe |)

    Inderjit

    Wednesday, July 22, 2015 8:18 AM
  • PS_Issue
    Wednesday, July 22, 2015 8:20 AM
  • damn whats now again ! Sorry for bather you so much
    Wednesday, July 22, 2015 8:21 AM
  • Hi Marcus,

    first of all the solution:

    Get-ADGroup "DEDRE-DMS-Lager" | Export-Csv "file.csv" -Delimiter ";" -NoTypeInformation

    You use the Pipe symbol ( "|" ) to pass the output of one command to the next. It threw an error, because you didn't pass anything to it (as you typed it in a new line).

    The "-NoTypeInformation" parameter to Export-Csv causes it to skip adding a line with the Type Name.

    The '-Delimiter ";"' parameter tells the command to use ";" as the delimiter (Trennzeichen) for the values. You need to use this if you want to open the csv in Excel by doubleklicking in a German Excel.

    Cheers,
    Fred


    There's no place like 127.0.0.1




    • Edited by FWN Wednesday, July 22, 2015 8:31 AM
    Wednesday, July 22, 2015 8:26 AM
  • PS_Issue
    Wednesday, July 22, 2015 8:31 AM
  • Thanx for your pation?!
    Wednesday, July 22, 2015 8:31 AM
  • Well ... this is a pretty plain error. Powershell can't write to the location you are trying to write to.

    # Old line
    Get-ADGroup "DEDRE-DMS-Lager" | Export-Csv "file.csv" -Delimiter ";" -NoTypeInformation
    
    # New Line
    Get-ADGroup "DEDRE-DMS-Lager" | Export-Csv "C:\temp\file.csv" -Delimiter ";" -NoTypeInformation

    This assumes there exists a folder C:\temp and that you do not need admin privileges to write to it. Change the path or file name as needed.


    There's no place like 127.0.0.1


    • Edited by FWN Wednesday, July 22, 2015 8:33 AM
    Wednesday, July 22, 2015 8:33 AM
  • PS_ISSUE
    Wednesday, July 22, 2015 9:06 AM
  • Mhh

    no names ? Why i do need the people that are in this group as an csv like:PS_Issue

    Wednesday, July 22, 2015 9:08 AM
  • Hi Marcus,

    well ... that's because you retrieved the group, not its members. We can fix that easily though:

    Get-ADGroup "DEDRE-DMS-Lager" -Property Members | Select -Expand Members | Get-ADUser -Properties DisplayName | Export-Csv "C:\temp\file.csv" -Delimiter ";" -NoTypeInformation

    What happens here? Well, first we tell the group to give us its members (which is a list of distinguished names like this: "CN=Max Mustermann,OU=TestOU,...").
    Then we pick those specific distinguished names and discard the rest of the information.
    Finally we use Get-ADUser to give us good information on each of those users.

    Note: This will throw errors (and not return information) if a group is member of the queried group. You can use Get-ADobject instead of Get-ADuser to fix that, but then you will have to more explicitely specify the properties you want.

    Cheers,
    Fred


    There's no place like 127.0.0.1


    • Edited by FWN Wednesday, July 22, 2015 9:23 AM
    Wednesday, July 22, 2015 9:20 AM
  • Thank you so much.It works so fine

    But there is one thing in common - when i add another group, would the csv get overwrite. I need a bunch of group names ?

    Thanx

    Marcus

    Wednesday, July 22, 2015 9:37 AM
  • Hi Marcus,

    well ... leaving it like this will certainly overwrite the file. Fortunately, we are using PowerShell, so there is a simple fix:

    $Groups = Get-Content "C:\temp\groups.txt"
    foreach ($Group in $Groups)
    {
        Get-ADGroup $Group -Property Members | Select -Expand Members | Get-ADUser -Properties DisplayName | Export-Csv "C:\temp\Group-Members-$($Group).csv" -Delimiter ";" -NoTypeInformation
    }

    Cheers,
    Fred

    Note: This script assumes you have the list of groups in a txt file (C:\temp\hroups.txt)


    There's no place like 127.0.0.1


    • Edited by FWN Wednesday, July 22, 2015 9:44 AM
    Wednesday, July 22, 2015 9:43 AM
  • Hey Fred,

    thank you so much - I will stay at the first variant, I just save them periodly

    Thanx great to know a guy like you !

    By the way - Do you know how to delete a outllok account from user via Powershell or a existing profile from user Tricky !?

    Thanx upfront

    Wednesday, July 22, 2015 12:45 PM
  • Hi Marcus,

    I'd have to look it up. Removing the outlook account is a mess, deleting the profile is fairly simple.

    However, since this is a completely new issue, please open a new question. This keeps the forum clean and makes it easier for other users that have the same question to find an answer.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Wednesday, July 22, 2015 12:49 PM
  • Hi There,

    does anybody know the script for:

    deleting a profile from user in outlook???

    BR

    Marcus

    Wednesday, July 22, 2015 2:43 PM
  • Hi Marcus,

    again, please create a new question (forum-thread) for this.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Wednesday, July 22, 2015 2:47 PM