Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a pclist.csv file like this:

| Name | LastLogonTimestamp | Some Other Data |
| 2342 | 23/05/2012         | Blah Blah Blah  |
| 3433 |                    | Yada Yada Yada  |

As you can see, some of the LastLogonTimestamp cells don't contain any data and some do.

I'm trying to examine this .csv using a powershell function like this:

$assets = import-csv pclist.csv

Function ActiveDesktop
foreach ($asset in $assets)
    if ($asset.'LastLogonTimestamp' -le {get-date.adddays(-90) -format "ddMMyyyy"})
        {write-host $asset.Name, $asset."LastLogonTimestamp"}

I want to see which PCs are inactive, but running the query doesn't return anything. Can anybody point me in the right direction?

share|improve this question
up vote 4 down vote accepted

Get all records with empty LastLogonTimestamp or older then 90 days:

.\Import-Csv pclist.csv | `
    ? { 
        $_.LastLogonTimestamp -eq "" -or `
        [DateTime]::Parse( $_.LastLogonTimestamp) -le [DateTime]::Today.AddDays(-90)
share|improve this answer
Works great, thanks. Just I think you accidentally left a leading space before the second $_.LastLogonTimestamp though. After removing that it worked as expected :-) – leftcase Aug 1 '12 at 10:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.