QAD-Cmdlets LastLogonTimestamp

ptea
ptea used Ask the Experts™
on
Hi there,

I want to run this query using the Qest AD Powershell extensions:

get-qaduser -Enabled -includeallproperties -Sizelimit 0 | select -property name,samaccountname,lastlogontimestamp

The query works but after some hundret accounts it failed with the following error message:
Get-QADUser : '040930075424Z' is not generalized time UTC string.
At line:1 char:12
+ get-qaduser <<<<  -Enabled -includeallproperties -Sizelimit 0 | select -property name,samaccountname,lastlogontimesta
mp
    + CategoryInfo          : NotSpecified: (:) [Get-QADUser], FormatException
    + FullyQualifiedErrorId : System.FormatException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetUserCmdlet


Anyboday knows how to get rid of this? thx
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chris DentPowerShell Developer
Top Expert 2010

Commented:

Neat...

It could be a bug. Lets see if we can dig a bit deeper. First we need to know who throws the error if we can. Debugging version attached.

Chris
$VerbosePreference = "continue"
Get-QADUser -Enabled -IncludeAllProperties -Sizelimit 0 | 
  ForEach-Object {
    # Attempt to get the timestamp, should throw an error
    $TimeStamp = $_.LastLogonTimeStamp
    # If it did. Write debugging information
    If (!$?) {
      $User = ([ADSISearcher]"(distinguishedName=$($_.DN))").FindOne()
      Write-Verbose "Name: $($_.Name)"
      Write-Verbose "TimeStamp (raw): $($User.Properties['lastlogontimestamp'][0])"
    }
 
    $_ | Select Name, Samaccountname, LastLogonTimeStamp
}

Open in new window

Author

Commented:
Thx Chris - but the debugging is not working... get the same message as before, no additional information...

cheers
Chris DentPowerShell Developer
Top Expert 2010

Commented:

Hmm okay, this one?

I'm hoping it won't error until it gets to:

$_ | Select Name, SamAccountName, LastLogonTimeStamp

If it dies before that it's going to be a little more difficult.

Chris
$VerbosePreference = "continue"
Get-QADUser -Enabled -IncludeAllProperties -Sizelimit 0 | 
  ForEach-Object {
    $User = ([ADSISearcher]"(distinguishedName=$($_.DN))").FindOne()
    Write-Verbose "Name: $($_.Name)"
    Write-Verbose "TimeStamp (raw): $($User.Properties['lastlogontimestamp'][0])"
 
    $_ | Select Name, Samaccountname, LastLogonTimeStamp
}

Open in new window

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Author

Commented:
...in principle nice stuff - get the debug information of each user account, but crashes at the same position without showing debug-info...

I run the query without LogonTimeStamp to get the object which is causing the troubles. Verified the values and for me everything is fine... (checked it with the Sysinternals AD Explorer)...

But when I run the query against this user account only I get the same error... hmm strange stuff - I hope this is the only account doing bad things, is it possible to exclude it?
Chris DentPowerShell Developer
Top Expert 2010

Commented:

You could feed it an LDAP filter to prevent it finding the account. e.g.

-LdapFilter "(!(name=TheBadAccount))"

It'd be nice to know why it's getting upset about the value though.

Chris

Author

Commented:
thx for the input... nice to be able to use normal LdapFilters - i did not know.... strange whats going on with this account.... Yeah would be nice to figgure it out - but I can't find the bug...

really bad - I used the filter with the samaccountname -> same result. I disabled the account temporary, as I am using the switch "-Enabled" only active account should be checked -> same result... So we have the problem not only with this account - I identified the 2nd account and excluded it too.

Do you know is there an option like "SilentlyContinue" available for WMI?

The really bad thing is, that the query stops...

Thx for the good support...



Chris DentPowerShell Developer
Top Expert 2010

Commented:

There is, but it may not do any good if it's throwing a terminating error.

For those accounts, can you run:

([ADSISearcher]"(&(name=The Name)(objectClass=user)(objectCategory=person))").FindAll() |
  Select-Object `
    @{n='Name';e={ $_.Properties["name"][0] }},
    @{n='lastLogonTimeStamp';e={ $_.Properties["lastlogontimestamp"][0] }}

It should give you a numeric value for lastLogonTimeStamp. Does it?

If so, please run:

[DateTime]::FromFileTime(TheNumericValue)

See if that gives you a sane date?

Chris
Commented:
everything is fine now - workaround is to use the "-includedproperties" switch.... as this works the problem was not to query the lastlogontimestamp, the problem is a different value stored in some accounts.

Thx for your help... cheers
Chris DentPowerShell Developer
Top Expert 2010

Commented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial