pramod1
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.
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.
Active employees? or Active and Inactive?
This should do it:
This pulls all the active users over the last 90 days.
$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'
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) }
ASKER
can I run separately for active and non active ? as per above command the above one pulls all active and non active both?
ASKER
I need employee name and AD user name in csv format
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)
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
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
ASKER
my manager needs the details ,w e are not doing clean up
ASKER
we just need employee name and AD user name in the result ( csv file)
ASKER
Get-ADUser -Filter 'Company -like "Alpha*"' -Properties * | Select -Property EmailAddress,GivenName,Sur name,Displ ayName,Tit le,Departm ent,Office ,OfficePho ne,MobileP hone,Fax,S treetAddre ss,City,St ate,Postal Code,Count ry | Export-CSV "C:\\ADusers.csv" -NoTypeInformation -Encoding UTF8
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) }
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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