0

I am currently trying to convert a date from the one displayed in regedit to a readable datetime format. But I do not know how to do this, I'm working with the following:

.GetValue('InstallDate')

And in the .csv file, it display it as this: 20150914

How would I go about converting that into a readable date?

1
  • It would be helpful if you posted the whole code where you take the value from registry and place it in the csv (not that I would not know how to do it, I am more curious about how you do it) Commented Oct 14, 2015 at 13:55

3 Answers 3

1

try

[datetime]::Parseexact("20150914","yyyyMMdd", $null  )
Sign up to request clarification or add additional context in comments.

Comments

1

I'm not sure why you down voted the other answer because he is right on the money with [Datetime]::ParseExact you will have to deal with the null values though

    $Regbase = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\
    foreach ($entry in $regBase)
    {
    $date = (Get-ItemProperty HKLM:\$entry | select installdate).installdate
        try
        {
            [DateTime]::ParseExact($date, "yyyyMMdd", [CultureInfo]::InvariantCulture) 
        }
        catch [exception] 
        {
            "Date Value: $date" 
        }
    }

Comments

0

PowerShell Date is just .NET DateTime. Check DateTime.ParseExact.

[DateTime]::ParseExact("20151010", "yyyyMMdd", [CultureInfo]::InvariantCulture)

1 Comment

Where would I place that? - this is the complete string: ($RegBase.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$_")).GetValue('InstallDate')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.