• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 603
  • Last Modified:

Export Active Directory Users Attribute of all users in a specify location


Anyone know a tools where I can set in a windows schedule  task that will export in a CSV the First name & Last Name & Email Address & Display name of all the user located in a specific OU.

I have a Domain Control running Windows Server 2008

1 Solution
Mike KlineCommented:
You can use powershell and get-aduser  also lookup adinfo (free gui tool)


Sarang TinguriaSr EngineerCommented:
change the names as per your naming convention and configure below command in scheduled task

dsquery user "OU,OUname,DC=domain,DC=local" -limit 0 | dsget user -display -email -pager>c:\Users.csv

Open in new window

Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
Command below will export all attributes for users:

Dsquery * -limit 0 -filter "&(objectClass=User)(objectCategory=Person)" -attr * >> output.txt
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

For exporting this can be done manually...

This scripts is tested scripts...

Hope it helps you.

Import-Module ActiveDirectory

#Create a variable for the date stamp in the log file
$LogDate = get-date -f yyyyMMddhhmm
#Sets the OU to do the base search for all user accounts, change for your env.
$SearchBase = "OU=****,DC=****,DC=com"
#Create an empty array for the log file
$LogArray = @()

$Users = @(Import-Csv "e:\temp\Leavers.csv")
ForEach ($User In $Users)
$Filter = "(company=" + $User."Employee ID" + ")"
$Return = Get-ADUser -searchbase $SearchBase -LDAPFilter $Filter
#Create new object for logging
If ($Return){
#Amend the users description
set-aduser $Return -Description ("Identified Leaver - Disabled on "+(get-date).toshortdatestring())
#Disables user object.
Disable-ADAccount $Return
#Moves the account
Move-ADObject $Return -TargetPath "OU=Users,OU=****,OU=Inactifs,DC=****,DC=com"
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name "Name" -Value $Return.name
$obj | Add-Member -MemberType NoteProperty -Name "Account Name" -Value $Return.samaccountname
$obj | Add-Member -MemberType NoteProperty -Name "Employee ID" -Value $User."Employee ID"
$obj | Add-Member -MemberType NoteProperty -Name "DistinguishedName" -Value $Return.DistinguishedName
#Adds object to the log array
$LogArray += $obj

#Exports log array to HTML file in the temp directory with a date and time stamp in the file name.
$a = "<style>"
$a = $a + "BODY{background-color:#D0D0D0;}"
$a = $a + "TABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 2px;padding: 0px;border-style: solid;border-color: black;background-color:#CC0000}"
$a = $a + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: black;background-color:#D0D0D0}"
$a = $a + "</style>"
$logArray | ConvertTo-HTML -head $a -body "<H2>Leavers Report</H2>"| Out-File "\\*****\Reports\Users_Leaver_Report_$logDate.html " 

##Creates and sends completion email with information##
$emailFrom = "AD-Scripts@*****.com"
$emailTo = "****.Admins@***.com"
$subject = "AD Users Leaver Script Complete"
$smtpServer = "*****"
$body = "The monthly AD Leavers script has run.`r`n"+
"Report is located \\*****\Reports\User_Leavers_Report_$logDate.html"

Send-MailMessage -To $emailTo -From $emailFrom -Subject $subject -Body $body -SmtpServer $smtpServer

youpaAuthor Commented:
This command work fine , however it's only giving the display name, I would like also to have First Name and Lastname.

dsquery user "OU,OUname,DC=domain,DC=local" -limit 0 | dsget user -display -email -pager>c:\Users.csv

Mike KlineCommented:
Just add a few more attributes and you should be good to go

dsquery user "OU,OUname,DC=domain,DC=local" -limit 0 | dsget user -display -email     -fn -ln pager>c:\Users.csv

List of attributes can be found  http://technet.microsoft.com/en-us/library/cc732535.aspx


Mike KlineCommented:
Thanks a lot for the points and glad to help.   Just a heads up next time you can also split points for several helpful answers.


youpaAuthor Commented:
Thanks all
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

We Need Your Input!

WatchGuard is currently running a beta program for our new macOS Host Sensor for our Threat Detection and Response service. We're looking for more macOS users to help provide insight and feedback to help us make the product even better. Please sign up for our beta program today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now