Solved

get-aduser syntax assistance

Posted on 2014-04-08
4
486 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 18

Accepted Solution

by:
Raheman M. Abdul earned 167 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now