Author Posts

July 4, 2014 at 1:16 am

Hello,

I'm trying to get a list from AD of computers that have not logged to the network in the last 60 days. I have the command worked and just need a bit of help with the date format. What I currently have is:

$LLDate = (Get-Date).AddDays(-60)
Get-ADComputer -Filter * -Properties Name, LastLogonDate, DistinguishedName |
 Where { $_.LastLogonDate -lt $LLDate } | Sort LastLogonDate -Descending |
 FT Name, LastLogonDate, DistinguishedName -AutoSize

This displays [blockquote]COLINS 31/07/2013 16:13:26 CN=COLINS,CN=Computers,DC=domain,DC=local
IT-TESTPC 25/07/2013 00:54:12 CN=IT-TESTPC,CN=Computers,DC=domain,DC=local
WASIMA 15/07/2013 10:55:46 CN=WASIMA,CN=Computers,DC=domain,DC=local[/blockquote]

Can I get the LastLogonDate to just display as dd/mm/yyyy format?

Thanks
Tony

July 4, 2014 at 2:24 am

Hello Tony,

Sure, try this:

$LLDate = (Get-Date).AddDays(-60)
Get-ADComputer -Filter * -Properties Name, LastLogonDate, DistinguishedName |
 Where { $_.LastLogonDate -lt $LLDate } | Sort LastLogonDate -Descending |
 FT Name, @{name="LastLogonDate";expression={($_.LastLogonDate).ToShortDateString()}}, DistinguishedName -AutoSize

The ToShortDateString() method displays only the day, month and year.

July 4, 2014 at 2:40 am

I've realized, I've updated my reply.
I think you can solve it with a calculated property by using the ToShortDateString() method on the LastLogonDate property.
However, I don't have access to an AD environment right now, so I can't test it, but it should work.

July 4, 2014 at 2:41 am

Works perfectly

Thanks