Home ยป How to Change Created Date of File in PowerShell

How to Change Created Date of File in PowerShell

You can change the created date of a file in PowerShell by updating the CreationTime property of the file object.

The following method shows how you can do it with syntax.

Method 1: Modify the creation date of a file

$file = Get-Item -Path  "C:\temp\log\top5process.txt"
$newCreationDate = [datetime]::Parse("05/02/2024 10:00:00")
$file.CreationTime = $newCreationDate

This example will update the creation date of a file.

The following example shows how you can change the creation date of a file in PowerShell.

Change the Creation Date of a File in PowerShell

You can change the creation date of a file in PowerShell by retrieving the file object details using the Get-Item cmdlet and updating the CreationTime property of the file object.

# define the path to the file
$filePath = "C:\temp\log\top5process.txt"

# Get the file object
$file = Get-Item -Path $filePath

# display the file object details
$file

# Set a new creation date
$newCreationDate = [datetime]::Parse("05/02/2024 10:00:00")

# Update the CreationTime property of the file object
$file.CreationTime = $newCreationDate

# Output the updated creation date of file
Write-Output "Updated creation date: $($file.CreationTime)"

Output:

PowerShell change created date of file
PowerShell change created date of a file

In this example, the $filePath variable stores the path to the file. We then get the file object using the Get-Item cmdlet and store it in the $file variable.

Next, we define a new creation date using the [datetime]::Parse("05/02/2024 10:00:00") and store it in the $newCreationDate Variable. This example sets the date to May 02, 2024, at 10:00 AM

Finally, we update the CreationTime property of the file object and output the updated file creation date using the Write-Output cmdlet.

After running the PowerShell script, it changes the created date of a file.

Conclusion

I hope the above article on changing the created date of a file in PowerShell is helpful to you.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.