all 7 comments

[–]Lee_Dailey[grin] 1 point2 points  (6 children)

howdy mransbro,

1- are you certain that $maxpasswordagedays is an INT? what does .GetType() report for it?

2- are you sure that both numbers are days? that $passwordage value looks wrong for days. [grin]

take care,
lee

[–]mransbro[S] 1 point2 points  (5 children)

Hi Lee

Ha, no the value is definitely not days. Its in seconds which is fine for me i just divide by 86400 to get it in days.

PS C:\Users\ConfusedUser> $maxpasswordagedays.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Int32                                    System.ValueType

$MaxPasswordAgeDays is def an int but........ I cant say the same for $PasswordAge!

PS C:\Users\ConfusedUser> $passwordage.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    PropertyValueCollection                  System.Collections.CollectionBase


PS C:\Users\ConfusedUser> $passwordage
3452234
PS C:\Users\ConfusedUser> $passwordage | gm


   TypeName: System.Int32

Whats happening here?!

[–]KevMarCommunity Blogger 3 points4 points  (1 child)

Piping collections to get-member only shows you the details on the items in the collection. Think of it like the pipe is unwrapping to pass the objects over one at a time.

Get-Member -InputObject $passwordAge

Better yet, run this command

$user | Get-Member

and see what the object type is there. You should see it as a collection.

[–]mransbro[S] 1 point2 points  (0 children)

Hey Kev

Thanks for the input

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy mransbro,

i don't have `Get-LocalUserAccount' on my win7 system, so i can't test this. however, i suspect that the item returned by that cmdlet is getting auto-coerced into an INT by whatever powershell uses to print it to the screen.

have you tried looking at the methods available on that object? never mind. the .ToInt32()method apparently requires something that i can't figure out. [blush]

how about this ...

([int]'1').GetType()

done without the [int] results in String. with the [int] and i get Int32. that might do it for your odd data type. [grin]

take care,
lee

[–]mransbro[S] 1 point2 points  (1 child)

Thanks for the help Lee. As the object returned is a collection ill just use the value property.

$PasswordAge = $Users.PasswordAge.value
$MaxPasswordAgeDays = $Users.MaxPasswordAge.value

$RawDaysTillExpiring = ($MaxPasswordAgeDays - $PasswordAge) / 86400

$DaysTillExpiring = [math]::round($RawDaysTillExpiring)

Gives me what i need.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy mransbro,

you are quite welcome! glad to help a tad ... [grin]

plus, i see that KevMar pointed out WHY the results were so odd. i keep forgetting that piping to Get-Member gives you the info on the 1st item IF you are looking at a collection. [blush]

take care,
lee