Home » How to Get File Creation Date in PowerShell

How to Get File Creation Date in PowerShell

To get the file creation date in PowerShell, you can use the Get-Item cmdlet to retrieve file information and then access the CreationTime property.

The following methods show how to use it with syntax.

Method 1: Get the file creation date using Get-Item cmdlet

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

# Get the creation date of a file

(Get-Item -Path $filePath).CreationTime

This example returns the creation date of a file in PowerShell.

Method 2: Get the file creation date using Get-ChildItem cmdlet

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

# Get the creation date of a file

(Get-ChildItem -Path $filePath).CreationTime

This example outputs the file creation date time to the console.

The following examples show how to use these methods.

Get the File Creation Date Using Get-Item Cmdlet in PowerShell

To get the file creation date in PowerShell, you can use the Get-Item cmdlet to retrieve the file information and then access the Creationtime property to get the creation date of a file.

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

# Get the creation date of a file

(Get-Item -Path $filePath).CreationTime

Output:

PowerShell get file creation date using get-item
PowerShell get file creation date using get-item

The output shows the creation date of a file.

Get the File Creation Date Using Get-ChildItem in PowerShell

Another way to get the file creation date is by using the Get-ChildItem cmdlet that retrieves the file information and then accesses the Creationtime property.

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

# Get the creation date of a file

(Get-ChildItem -Path $filePath).CreationTime

Output:

PowerShell get file creation date using get-childitem
PowerShell get file creation date using get-childitem

The output shows the creation date of a file specified by the $filePath variable.

Conclusion

I hope the above article on getting the file creation date in PowerShell is helpful to you.

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