Script to find the create date of old folders & rewrite it to new folders

I just moved all of my folders/files from an OLD HDD to a NEW HDD. The files on the NEW HDD maintained their created date but the folders now have a create date of TODAY. Can someone please write me a script where it copies the create date of the OLD folders on the OLD HDD and rewrite it to the NEW folders on the NEW HDD.

As of now I have found this to write new dates one by one:

(Get-Item "Z:wwwnewfolder").LastWriteTime=("25 May 2021 00:00:00")

I have over 500 folders so I don’t want to do each and every folder.

Answer

ok… so I actually found a script someone wrote and took out a few things and it worked like a charm…

$src = "G:sourcefolder"
$dest = "Z:destinationfolder"
$src = $src.Replace("","\")

$i = Get-ChildItem -Path $src -Recurse
$i | % {     ## -- All files and folders

    $apath = $_.FullName -Replace $src,""
    $cpath = $dest + $apath

    If (Test-Path $cpath)
       {
           Set-ItemProperty -Path $cpath -Name CreationTime -Value $_.CreationTime
           Set-ItemProperty -Path $cpath -Name LastWriteTime -Value $_.LastWriteTime
           Set-ItemProperty -Path $cpath -Name LastAccessTime -Value $_.LastAccessTime
       }
    }

$d = Get-ChildItem -Path $src -Recurse -Directory
$d | % {     ## -- Folders only

    $apath = $_.FullName -Replace $src,""
    $cpath = $dest + $apath

    If (Test-Path $cpath)
       {
           Set-ItemProperty -Path $cpath -Name CreationTime -Value $_.CreationTime
           Set-ItemProperty -Path $cpath -Name LastWriteTime -Value $_.LastWriteTime
           Set-ItemProperty -Path $cpath -Name LastAccessTime -Value $_.LastAccessTime
       }
    }