Hi there,
does anyone can provide me a script to create a CSV. out of from AD via powershell script
Technology Tips and News
Hi there,
does anyone can provide me a script to create a CSV. out of from AD via powershell script
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.
Thanx fo the quick answer!
Do I have to set in the AD modul in Powershell.
Whats the script for the AD Modul if so?
Thanx
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
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?
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
Thank so much guyz,
but Iam still have no success:
Hi Marcus,
does it throw an error? If yes, please post the error.
Cheers,
Fred
Hello Fred,
above thats the error message I'am gonna get.
The group is, please see screenshot below
Even with my delegation account?
Whoch rights do i need
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
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,
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
Mhh
no names ? Why i do need the people that are in this group as an csv like:
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,
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
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
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
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
Hi There,
does anybody know the script for:
deleting a profile from user in outlook???
BR
Marcus
Hi Marcus,
again, please create a new question (forum-thread) for this.
Cheers,
Fred