Reputation: 183
I want to calculate the age of the password, in days, using the PasswordLastSet property. I've created the below code but Password Age never outputs anything. I'm guessing there is a type error but I'm not sure how to convert to DateTime. Any thoughts?
Get-ADComputer myComputer -Properties PasswordLastSet | Select-Object -Property PasswordLastSet, @{Name = 'Password Age';Expression = {Get-Date - ([datetime]($_.PasswordLastSet))}}
Upvotes: 0
Views: 3481
Reputation: 7489
The reason for the failure is the lack of parens around the Get-Date
call. Without those parens, the cmdlet tries to use the remainder of the line as input ... [grin] wrapping the cmdlet in parens - (Get-Date)
- forces the cmdlet to run without trying to parse the remainder of the line.
Upvotes: 3