PowerShell: File attributes: Change date - without any tools.
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"))
Video
Alternative
The PowerShell offers here a simple alternative to special programs like e.g. Attribute-Changer

{{percentage}} % positive

THANK YOU for your review!
Top articles in this section
Log files in PowerShell can be created via the Out-File command, via a custom function, or via PowerShell's built-in Transcript.
PowerShell uses the following commands to open a socket on a specific port via System.NET:
Alternatively, if you can't change the screen lock settings, you can move the mouse regularly, or have a script move the mouse. Originally published as an AutoIt script, I recreated the script with a few PowerShell lines. Anyone who copies the following commands into a PowerShell session will prevent the computer from locking the screen or starting the screensaver: