AD groups in a csv.

Hi there,

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

July 16th, 2015 3:58am

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.

Free Windows Admin Tool Kit Click here and download it now
July 16th, 2015 4:09am

Thanx fo the quick answer!

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

July 16th, 2015 4:39am

Whats the script for the AD Modul if so?

Thanx

Free Windows Admin Tool Kit Click here and download it now
July 16th, 2015 4:41am

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

July 16th, 2015 5:02am

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?

Free Windows Admin Tool Kit Click here and download it now
July 20th, 2015 10:47am

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

Free Windows Admin Tool Kit Click here and download it now
July 20th, 2015 11:19am

Thank so much guyz,

but Iam still have no success:

July 21st, 2015 10:45am

Hi Marcus,

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

Cheers,
Fred

Free Windows Admin Tool Kit Click here and download it now
July 21st, 2015 11:09am

issue error
July 22nd, 2015 3:08am

Hello Fred,

above thats the error message I'am gonna get.

The group is, please see screenshot belowgROUP

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 3:10am

You do not have access to the file
July 22nd, 2015 3:14am

Even with my delegation account?

Whoch rights do i need

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 3:36am

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

July 22nd, 2015 3:43am

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 4:13am

i think that worked and now? How do i get it in CSV?
July 22nd, 2015 4:14am

after the command use | export-csv c:\temp\csvfilename.csv (use pipe |)
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 4:18am

PS_Issue
July 22nd, 2015 4:21am

damn whats now again ! Sorry for bather you so much
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 4:21am

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,

July 22nd, 2015 4:27am

PS_Issue
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 4:32am

Thanx for your pation?!
July 22nd, 2015 4:32am

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 n

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 4:34am

PS_ISSUE
July 22nd, 2015 5:07am

Mhh

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

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 5:09am

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,

July 22nd, 2015 5:20am

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

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 5:38am

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\hroup

July 22nd, 2015 5:44am

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

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 8:45am

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

July 22nd, 2015 8:49am

Hi There,

does anybody know the script for:

deleting a profile from user in outlook???

BR

Marcus

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 10:44am

Hi Marcus,

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

Cheers,
Fred

July 22nd, 2015 10:48am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics