Thanks to the user Vesper I have been able to get this far with my Powershell script.
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=REMOVEDFORANONYMITY,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_$($_.name).csv"}
However, when I run this script I get the following errors:
Is there something I am missing?
I am also wanting to make it to where not only does it grab LastLogon, but also grab LastLogonTimeStamp and then have is use whichever is the most recent. My Powershell knowledge is very small, can anyone add to my script what is needed? Thanks in advance.
You seem to have pasted the
LastLogon,
part of theProperties
argument from somewhere.There are two zero-width unicode characters (
U+200C
andU+200B
) betweenLastLogon
and,
.Delete it and rewrite it by hand