It will change creation time of fileName.txt
1 |
Get-ChildItem "fileName.txt" | Foreach-Object { $_.CreationTime = '1/1/2020 12:34'} |
It will change values $TimeType of all files in $Folder
1 2 3 4 5 6 7 8 9 |
$Folder = Get-ChildItem "C:\temp\test\*" $FileTime = "3/10/1982 06:30" $TimeType = ("CreationTime", "LastWriteTime", "LastAccessTime") foreach ($File in $Folder) { foreach ($Time in $TimeType) { Get-ChildItem "$File" | Foreach-Object {$_."$Time" = "$FileTime"} } } |
It will change values $TimeSettings of all files in $Folder using Hash Table
1 2 3 4 5 6 7 8 9 10 |
$Folder = Get-ChildItem "C:\temp\test\*" $TimeSettings = @{'CreationTime' = '3/10/1975 06:30'; 'LastWriteTime' = '3/10/1982 06:30'; 'LastAccessTime' = '5/21/2012 13:30'} foreach ($File in $Folder) { $TimeSettings.GetEnumerator() | Foreach-Object { $FileProperty = $_.Key $DateValue = $_.Value Get-ChildItem "$File" | Foreach-Object {$_."$FileProperty" = "$DateValue"} } } |