Reputation: 3
I am trying to get the PasswordLastSet property from Active Directory as a dateTime variable, but I only know how to get it as an object. Eventually I want to compare that date with the current date to see how many days are remaining, but I can't figure out how to get it into DateTime format.
I've tried using get-aduser in different ways but I can't seem to get the date as a DateTime.
$serviceAccount = 'serviceAccountName'
$expDate = get-aduser $serviceAccount -properties * | ft passwordlastset
$expDate.GetType()
I would like to get a DateTime result, but I keep getting an object.
Upvotes: 0
Views: 4631
Reputation: 36342
Never pipe to a Format-*
cmdlet and then capture the output. Those are intended for formatting output to screen. Instead use |Select-Object -Expand passwordlastset
. What you captured is a formatting object.
$serviceAccount = 'serviceAccountName'
$expDate = get-aduser $serviceAccount -properties * | Select-Object -Expand passwordlastset
Or a shorter version would be:
$serviceAccount = 'serviceAccountName'
$expDate = get-aduser $serviceAccount -properties * | % passwordlastset
Upvotes: 2