Cmdlets

Choose a cmdlet from the list on the left or search for a specific cmdlet. Choose a cmdlet from the list or search for a specific cmdlet.
About Help  Providers
 

Set-FileTime

Set-FileTime

pscx.dll

Synopsis

PSCX Cmdlet: Sets a file or folder's created and last accessed/write times.

Syntax

Set-FileTime [-Path] [-Time] [-Accessed] [-Created] [-Force] [-Modified] [-PassThru] [-UseTimeFromFile] [-Utc] [<CommonParameters>]

Set-FileTime [-LiteralPath] [-Time] [-Accessed] [-Created] [-Force] [-Modified] [-PassThru] [-UseTimeFromFile] [-Utc] [<CommonParameters>]

Detailed Description

Sets a file or folder's created and last accessed/write times.

Parameters

-LiteralPath <String[]>

Specifies a path to the item. The value of -LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

Aliases

None

Required?

true

Position

1

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-Path <String[]>

Specifies the path to the file to process. Wildcard syntax is allowed.

Aliases

None

Required?

true

Position

1

Default value

None

Accept pipeline input?

true (ByValue, ByPropertyName)

Accept wildcard characters?

true

-Time <DateTime>

The time to use to set the access, created and modified times unless -Accessed, -Created and/or -Modified is specified, then only those times will be updated.

Aliases

None

Required?

false

Position

2

Default value

The current system time

Accept pipeline input?

false

Accept wildcard characters?

false

-Accessed <SwitchParameter>

Update the accessed time. Created and modified time will not be updated unless also specified. Parameter alias is SetAccessedTime.

Aliases

None

Required?

false

Position

named

Default value

True

Accept pipeline input?

false

Accept wildcard characters?

false

-Created <SwitchParameter>

Update the created time. Accessed and modified time will not be upated unless also specified. Parameter alias is SetCreatedTime.

Aliases

None

Required?

false

Position

named

Default value

False

Accept pipeline input?

false

Accept wildcard characters?

false

-Force <SwitchParameter>

Attempt to set the specified time even if the file is readonly.

Aliases

None

Required?

false

Position

named

Default value

False

Accept pipeline input?

false

Accept wildcard characters?

false

-Modified <SwitchParameter>

Update the modified time. Accessed and created time will not be updated unless also specified. Parameter alias is SetModifiedTime.

Aliases

None

Required?

false

Position

named

Default value

True

Accept pipeline input?

false

Accept wildcard characters?

false

-PassThru <SwitchParameter>

Passing the processing path to the next stage of the pipeline.

Aliases

None

Required?

false

Position

named

Default value

False

Accept pipeline input?

false

Accept wildcard characters?

false

-UseTimeFromFile <String>

Use the date and time from the file at the specified path to set the access and/or write times.

Aliases

None

Required?

false

Position

named

Default value

None

Accept pipeline input?

false

Accept wildcard characters?

false

-Utc <SwitchParameter>

Set the accessed, created and/or modified times as UTC times.

Aliases

None

Required?

false

Position

named

Default value

False

Accept pipeline input?

false

Accept wildcard characters?

false

Input Type


Return Type


Notes

Examples

-------------------------- EXAMPLE 1 --------------------------

Updates the LastWriteTime and LastAccessTime properties of the file foo.txt to the current local time.

C:PS> Set-FileTime foo.txt

-------------------------- EXAMPLE 2 --------------------------

Updates the LastWriteTime and LastAccessTime properties of the file foo.txt to the current local time minus 14 days.

C:PS> Set-FileTime foo.txt -Time ((get-date).AddDays(-14))

-------------------------- EXAMPLE 3 --------------------------

Updates the LastWriteTime and LastAccessTime properties on all files with extension .CS in the current dir and below to the current local time.

C:PS> Get-ChildItem . *.cs -r | Set-FileTime

-------------------------- EXAMPLE 4 --------------------------

Updates only the LastWriteTime property on all files with extension .CS in the current dir and below to the current local time.

C:PS> Get-ChildItem . *.cs -r | Set-FileTime -Modified

-------------------------- EXAMPLE 5 --------------------------

Updates the LastWriteTime and LastAccessTime properties on all files with extension .CS in the current dir and below to the same time as the LastWriteTime of the file C:\boot.ini.

C:PS> Get-ChildItem . *.cs -r | Set-FileTime -UseTimeFromFile C:\boot.ini