0

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?

1 Answer 1

4

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)
    }
1
  • 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, 2012 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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