Read a file’s size and modified time with PowerShell Get-Item

  • Published: 2026.11.19
  • Updated: 2026.11.19
  • Windows

When you are checking a log or backup file, its size and last modified time can be useful before you open its contents. PowerShell can retrieve these details with Get-Item and display just the properties you need.

These examples work in Windows PowerShell 5.1 and PowerShell 7. Replace report[final].txt with your file’s path. A path beginning with .\ starts at the current working location.


Display a file’s size and modified time

From the folder containing the file, run:

Get-Item -LiteralPath '.\report[final].txt' |
    Select-Object Name, Length, LastWriteTime

Get-Item retrieves the file object. Select-Object chooses which properties to display. A sample file produced this result; the date’s display format depends on the session’s culture.

Name              Length LastWriteTime
----              ------ -------------
report[final].txt   4096 2026/11/01 9:30:00

Name is the filename, Length is the size in bytes, and LastWriteTime is the last modified time. In this example, the file contains 4096 bytes and has a last modified time of November 1, 2026, at 09:30. Retrieving these properties does not require reading the file’s text.

-LiteralPath treats the supplied path as a literal name. This matters for names containing square brackets, because -Path interprets wildcard characters.

Read only the size in bytes

To use the size as a number rather than a displayed table, access the file object’s .Length property:

(Get-Item -LiteralPath '.\report[final].txt').Length

For the same sample file, the result was:

4096

The unit is bytes. This can help you notice an unexpectedly empty backup file, but a size check is only one step: open the file in the relevant application or test a restore to check whether you can use the backup.

Format the last modified time consistently

When copying a timestamp into a record, pass a format string to ToString:

(Get-Item -LiteralPath '.\report[final].txt').LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')

The same file returned:

2026-11-01 09:30:00

MM means month, mm means minute, and HH means the hour using a 24-hour clock. Letter case changes the meaning. This command formats the property for display; it does not change the file’s timestamp.

Check a missing or hidden file

A nonexistent path makes Get-Item report an error. Do not treat that error as a zero-byte file: check the filename and location first. If the working folder is uncertain, put the full path inside the quotes.

Use -Force to retrieve a hidden file. This example uses a hidden file named hidden.txt:

Get-Item -LiteralPath '.\hidden.txt' -Force |
    Select-Object Name, Length

-Force does not override access permissions. An access-denied error and a missing path therefore need different checks.

Use a listing when you need to find the file

Passing a directory’s path to Get-Item retrieves that directory. It does not put the combined size of its contents into Length.

Use Get-Item when you know the file’s name. To find files by extension or search subfolders, see filtering a file listing with Get-ChildItem.

References

このブラウザからの自分のアクセスを解析から除外できます。