Reputation: 13
I am new-ish to PowerShell and am having a problem. I am trying to get a users password last set date and time from a domain and then add 90 days to it. So far I have:
$PLS_date = (get-aduser randomuser -Properties PasswordLastSet | Select passwordlastset) | out-string
"Password will expire on $((get-date).adddays(90)($PLS_date))"
However this spits out an error:
+ "Password will expire on $((get-date).adddays(90)($PLS_date))"
+ ~
Unexpected token '(' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
I have search around to try and find what i am doing wrong but cannot figure it out.
Help!
Upvotes: 1
Views: 261
Reputation: 24585
Try it this way:
$pwdLastSet = Get-ADUser username -Properties PasswordLastSet | Select-Object -ExpandProperty PasswordLastSet
if ( $pwdLastSet ) {
"Password will expire on: {0}" -f $pwdLastSet.AddDays(90)
}
Upvotes: 1