PowerShell: File attributes: Change date - without any tools.

Diese Seite gibt es auch in Deutsch

As an alternative to special programs, the date of a file or folder can also be changed with PowerShell. 

Change modification date (Modified on, modified)

The command get-item loads a file or folder and its properties and offers the possibility to rewrite some of the properties:

Here the setting of the modification date in one line:

$(get-item c:\temp\x.png).LastWriteTime = (Get-Date("2020-03-22 16:22")) 

Alternatively, the file could of course be loaded into a variable first and the properties rewritten afterwards:

$file = get-item c:\temp\x.png
$file.LastWriteTime = (Get-Date)

(Get-Date without specifying a date uses the current date)

Change creation date (CreationTime)

$(get-item c:\temp\x.png).CreationTime = (Get-Date("2020-03-22 16:22"))

change last access (LastAccessTime)

$(get-item c:\temp\x.png).LastAccessTime = (Get-Date("2020-03-22 16:22"))

Alternative

The PowerShell offers here a simple alternative to special programs like e.g. Attribute-Changer

positive Bewertung({{pro_count}})
Rate Post:
{{percentage}} % positive
negative Bewertung({{con_count}})

THANK YOU for your review!


Top articles in this section

PowerShell Log-Files: Logging into a textfile - write to file

PowerShell Log-Files: Logging into a textfile - write to file

created: 05.05.2022 from Bernhard

Log files in PowerShell can be created via the Out-File command, via a custom function, or via PowerShell's built-in Transcript. ... continue reading

Preview PowerShell text file and csv read / write

PowerShell text file and csv read / write

created: 02.05.2022 from Bernhard

PowerShell text file and csv read / write ... continue reading

PowerShell Loops and Array

PowerShell Loops and Array

created: 02.05.2022 from Bernhard

An array stores multiple values, similar to a 2-column table. ... continue reading


Questions / Comments