In my Previous AD Powershell Post, I have showed how to generate AD Computers report with specific Paramenters,
Wherein the LastLogonDate attribute value format will not be in the same format if your AD Infrastructure is not configured with specific time format.
Below output report is an example,You will see the report date values are has DD-MM-YYYY MM:mm and MM/DD/YYYY MM:mm.
You can apply filter and you will definitely find a difficulty when you need it well aligned for audit purpose.
Solution:
We have an Option to get this resolved, Here we go,
Get-Adcomputer -resultsetsize 100000 -Filter * -properties CanonicalName,DNSHostName,Enabled,IPv4Address,lastLogon,LastLogonDate,lastLogonTimestamp,Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion,whenCreated | select CanonicalName,DNSHostName,Enabled,IPv4Address,lastLogon,LastLogonDate,lastLogonTimestamp,Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion,whenCreated,@{Name=”ModifiedLastLogonDate”;Expression={$_.LastLogonDate.ToString(“yyyy-MM-dd HH:mm”)}} | export-csv Computers.csv
What is different here, In the above Powershell command, I have hooked up with Expression which is helping to convert to whatever format required.
@{Name=”ModifiedLastLogonDate”;Expression={$_.LastLogonDate.ToString(“yyyy-MM-dd HH:mm”)}}
Expression is used to convert Lastlogondate to the String with specific format. You can see the reports are added with additional Column called ModifiedLastLogonDate that you can filter with well aligned.