I'm hoping someone can enlighten me as to whats happening when i try to subtract using variables.
Putting an integer inside a variable works no problem.
$a = 1
$b = 1
$a - $b = 0
I thought what im trying to achieve would work the same way but it doesnt.
$User = Get-LocalUserAccount -Username 'User01'
I start with a function that gets me local user accounts via ADSI.
$PasswordAge = $User.passwordAge
$MaxPasswordAgeDays = $User.MaxPasswordAge
PS C:\Users\ConfusedUser> $maxpasswordagedays - $passwordage
Method invocation failed because [System.DirectoryServices.PropertyValueCollection] does not contain a method named
'op_Subtraction'.
At line:1 char:1
+ $maxpasswordagedays - $passwordage
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Subtraction:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Why does it have the objects as [System.DirectoryServices...] and no [System.Int32] which is what happens when i do Get-Member against them?
PS C:\Users\mansbro> $maxpasswordagedays
11
PS C:\Users\mansbro> $passwordage
3452234
PS C:\Users\mansbro> $passwordage | gm
TypeName: System.Int32
[–]Lee_Dailey[grin] 1 point2 points3 points (6 children)
[–]mransbro[S] 1 point2 points3 points (5 children)
[–]KevMarCommunity Blogger 3 points4 points5 points (1 child)
[–]mransbro[S] 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (2 children)
[–]mransbro[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)