Solved

get-aduser syntax assistance

Posted on 2014-04-08
4
501 Views
Last Modified: 2014-04-29
Does anyone know how to use the get-aduser to list all ad users and all attributes associated with those users, and output the results into csv?

I am not to fussed about an alternative I would like to stick with powershell and this cmdlet.

I'd also be very interested if there is a get-adgroup equiv that can list all ad groups and their members?
0
Comment
Question by:pma111
4 Comments
 
LVL 19

Accepted Solution

by:
Raheman M. Abdul earned 167 total points
ID: 39985921
Try this:

Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,whenCreated,Enabled,Organization | Sort-Object -Property Name | Export-Csv -path C:\temp\ADusers.csv

or
Get-ADUser -Filter * -Properties * | Sort-Object -Property Name | Export-Csv -path C:\temp\ADusers.csv

For details: http://technet.microsoft.com/en-us/library/ee617241.aspx

You can also get help on this cmdlet using:

get-help get-aduser -detailed
or
get-help get-aduser -examples
0
 
LVL 3

Author Comment

by:pma111
ID: 39985935
Does the second of the 2 list all user attributes?

And assistance on a cmdlet for listing all groups in AD and their members, again exported to CSV?
0
 
LVL 2

Assisted Solution

by:aishwarya1412
aishwarya1412 earned 167 total points
ID: 39985946
To get group members you can use:

Get-ADGroupMember [-Identity] <ADGroup> [-AuthType {<Negotiate> | <Basic>}] [-Credential <PSCredential>] [-Partition <string>] [-Recursive <switch>] [-Server <string>] [<CommonParameters>]


You can also check http://pipe2text.com/?page_id=1218
0
 
LVL 14

Assisted Solution

by:Justin Yeung
Justin Yeung earned 166 total points
ID: 39985954
for get-aduser to get all attributes
Import-Module ActiveDirectory
$OutPath = "C:\ADUsers.csv"
Get-AdUser -Filter * -Properties * | Select-Object * | Export-Csv $Outpath

Open in new window


for get-adgroups and all adgroup members to a spreadsheet
function Get-GroupHierarchy ($searchGroup)
{
$groupMember = get-adgroupmember $searchGroup | sort-object objectClass -descending
   foreach ($member in $groupMember)
    {
if ($member.objectclass -eq "user")
{
$userinfo = get-aduser $member.samaccountname -Properties *
}
if ($member.objectclass -eq "group")
{
$groupinfo = get-adgroup $member}
$array = @()
$Properties = @{"Group Name"=$groupinfo.name;Name=$member.Name;SamAccountName=$member.samaccountname;"Canonical Name"=$Userinfo.canonicalname}
$Newobject = New-Object  PSObject -Property  $Properties
$Array +=$Newobject

$outpath = "C:\ADgroups.csv"

$Array | Select-Object "Group Name",Name,SamAccountName,"Canonical Name" | export-csv $outpath -Append

    if ($member.ObjectClass -eq "group")
        {Get-GroupHierarchy $member.name}}
} 

$ADGroups = Get-AdGroup -Filter * -Properties *
foreach ($AdGroup in $AdGroups)
{
Get-GroupHierarchy $Adgroup.Name
}

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question