Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

how to convert a string value to date

$
0
0

Dear All,

I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.

but when i try to convert the variable to date value, I am getting the error as below.

Please help me......

PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
PS C:\script> $passwordSetDate

PasswordLastSet
---------------
7/15/2014 8:17:24 PM


PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
Cannot find an overload for "ParseExact" and the argument count: "3".
At line:1 char:1
+ $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>