Link to home
Start Free TrialLog in
Avatar of pramod1
pramod1Flag for United States of America

asked on

active directory

i am looking to pull all employess name name .

for this i need to create CSV file that includes two fields:  Employee Name and AD user name for all employees.  

any command shell you can recommend.
Avatar of Arjun Vyavahare
Arjun Vyavahare
Flag of India image

Hi,

Refer following link which contains the Powershell script from Microsoft, and also refer GUI based option to export -

https://gallery.technet.microsoft.com/scriptcenter/Powershell-script-to-5edcdaea

https://www.codetwo.com/admins-blog/export-users-from-active-directory/

Cheers,
Arjun
Avatar of ITguy565
Active employees? or Active and Inactive?
This should do it:

$oldDate = (Get-Date).AddDays(-90).ToFileTime().toString()
Get-ADUser -SearchBase 'cn=Users,dc=contoso,dc=local' -Properties lastlogontimestamp -LDAPFilter "(lastlogontimestamp>=$oldDate)" | 
    select @{n='User';e={$_.name}}, @{n='LastLogOn';e={[datetime]::FromFileTime($_.lastlogontimestamp)}} |
    ConvertTo-Html -Title 'Recent Users' | Out-File 'RecentUsers.html'
Invoke-Item 'RecentUsers.html'

Open in new window


This pulls all the active users over the last 90 days.
Here is another way.

Get-ADUser -Properties lastlogondate -Filter * | select name, lastlogondate | where { $_.lastlogondate -gt (Get-Date).AddDays(-90) }

Open in new window

Avatar of pramod1

ASKER

can I run separately for active and non active ? as per above command the above one pulls all active and non active both?
Avatar of pramod1

ASKER

I need employee name and AD user name in csv format
Avatar of pramod1

ASKER

als o I need to pipe it out to cs v file
If you are doing this as preparation for account deletion of cleanup you might find my ADCleanup application useful

Active Directory Cleanup Tool (ADCleanup)
ADCleanup is my implementation of a set-and-forget Active Directory cleanup tool. Once this tool is implemented correctly, you never need to worry about dormant accounts ever again.
https://www.experts-exchange.com/articles/30820/Active-Directory-Cleanup-Tool-ADCleanup.html
Avatar of pramod1

ASKER

Get-ADUser -Properties lastlogondate -Filter * | select name, lastlogondate | where { $_.lastlogondate -gt (Get-Date).AddDays(-90) } | Export-CSV c:\employess.csv this is working but not pulling employee name and AD username
Avatar of pramod1

ASKER

my manager needs the details ,w e are not doing clean up
Avatar of pramod1

ASKER

we just need employee name and AD user name in the result ( csv file)
Avatar of pramod1

ASKER

Get-ADUser -Filter 'Company -like "Alpha*"' -Properties * | Select -Property EmailAddress,GivenName,Surname,DisplayName,Title,Department,Office,OfficePhone,MobilePhone,Fax,StreetAddress,City,State,PostalCode,Country | Export-CSV "C:\\ADusers.csv" -NoTypeInformation -Encoding UTF8
Avatar of pramod1

ASKER

how  can I make changes in above with regard to Employee Name and AD user name  on above command
@Pramod, I will get the command for you shortly working on it now.
Does this give you what you are looking for.. If not tell me what I am missing :

Get-ADUser -Properties lastlogondate, Name, Displayname, Enabled -Filter * | select Displayname, name, lastlogondate, enabled | where { $_.lastlogondate -gt (Get-Date).AddDays(-90) }

Open in new window


Get-ADUser -Properties lastlogondate, Name, Displayname, Enabled -Filter * | select Displayname, name, lastlogondate, enabled | where { $_.lastlogondate -gt (Get-Date).AddDays(-90) }|Export-csv -notypeinformation -path c:\temp\users.csv

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of FOX
FOX
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial