PowerShell: How to Get File Creation Date


You can use the following methods in PowerShell to get the creation date of a specific file:

Method 1: Get Creation Date of Specific File

Get-ChildItem -Path c:\users\bobbi\nba_data.csv | select CreationTime

This particular example will return the date and time that the file nba_data.csv was created.

Method 2: Get Creation Date of All Files in Folder

Get-ChildItem -Path c:\users\bobbi\data1 -File | select Name, CreationTime | sort CreationTime

This particular example will return the date and time that each file in the data1 folder was created, sorted by creation time from oldest to newest.

The following examples show how to use each method in practice.

Example 1: How to Get Creation Date of Specific File in PowerShell

Suppose that we have a file saved in the following location:

  • c:\users\bobbi\data1\nba_data.csv

Suppose that we would like to check when this file was created.

We can use the following syntax to do so:

Get-ChildItem -Path c:\users\bobbi\nba_data.csv | select CreationTime

The following screenshot shows how to use this syntax in practice:

PowerShell get file creation date

The output displays the date and time when the file was created:

  • 3/11/2024 2:27:21 PM

Example 2: How to Get Creation Date of All Files in Folder in PowerShell

Suppose that we have a folder with the following location:

  • c:\users\bobbi\data1

Suppose that we would like to check when each file in the folder was created.

We can use the following syntax to do so:

Get-ChildItem -Path c:\users\bobbi\data1 -File | select Name, CreationTime | sort CreationTime

The following screenshot shows how to use this syntax in practice:

PowerShell get creation date of all files in folder sorted

The output displays the date and time when each file in the folder was created, sorted from oldest to newest creation date.

If you would instead like to sort by creation date from newest to oldest, you can add the -descending operator at the end:

Get-ChildItem -Path c:\users\bobbi\data1 -File | select Name,CreationTime | sort CreationTime -descending

The following screenshot shows how to use this syntax in practice:

The output now displays the date and time when each file in the folder was created, sorted from newest to oldest creation date.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Check if File Contains Specific String
PowerShell: How to Get List of Files Modified After Certain Date
PowerShell: How to Check if File Has Been Modified in last 24 Hours

Leave a Reply