So far I have this:
Get-ADDomainController -filter * |
% {Get-ADUser -Filter "Enabled -eq 'True'" -server $_.name -Properties Name,SamAccountName,Description,EmployeeID,EmployeeNumber,EmailAddress,LastLogon,Manager,Title,Department,Organization,Enabled -SearchBase "DC=webcoindustries,DC=com" |
? {$_.EmployeeID -notlike "EXCLUDE" } |
Select Name,SamAccountName,Description,EmployeeID,EmployeeNumber,EmailAddress,@{N='LastLogon'; E={[DateTime]::FromFileTime($_.LastLogon)}},Manager,Title,Department,Organization,Enabled |
Export-Csv "C:\scripts\AD_Export_Test\AD_Export_$($_.name).csv"}
This only pulls LastLogon into multiple CSV files (1 for each Domain Controller). However, what I would like to be done is for the script to also pull LastLogonTimeStamp, compare the two, and use the whichever one is most recent. I also would like to have the full end result only be in one final CSV file. Is this possible all in one script?
I think a simple
Group
, followed bySort
, andSelect -First 1
in aForEach
loop would solve this problem.I also moved your
EmployeeID -notlike "EXCLUDE"
filter from theWhere
statement into yourGet-ADUser
filter, and got rid of theWhere
statement