- 作者:佚名
- 时间:2017-10-10
PowerShell是Microsoft Windows操作系统的任何现代版本的一部分。 微软转移到PowerShell远离Windows 10上的命令提示符,但没有删除命令提示符这样做。
Windows 10的用户和管理员都可以访问这两者,但开发重点在于PowerShell。
Windows上的每个文件以及其他操作系统都具有与之相关联的几个时间戳。 文件系统跟踪文件创建时间,上次访问时间和最后写入时间。
如何使用Windows PowerShell编辑时间戳
您需要的三个命令如下:
$(Get-Item FILENAME.EXT).creationtime=$(DATE)
$(Get-Item FILENAME.EXT).lastaccesstime=$(DATE)
$(Get-Item FILENAME.EXT).lastwritetime=$(DATE)
注意:由于性能问题,默认情况下,所有受支持版本的Windows都不会启用上次访问时间。
给你一些例子:
$(Get-Item test.txt).creationtime=$(Get-Date)
$(Get-Item test.txt).lastaccesstime=$(Get-Date "12/24/2011 07:15 am")
请注意,该命令要求该文件位于PowerShell提示符的当前目录中。
有用的命令
一旦可能有用的是在运行PowerShell命令之前和之后列出当前文件夹的文件时间戳。 这样可以更容易地查找仍需要更改的文件,并检查更改是否已正确应用。
Get-ChildItem -force | Select-Object Mode, Name, CreationTime, LastAccessTime, LastWriteTime | ft
![](https://img.maotaopan.com/d/file/pic_jc/20210115/2017101012345128.png)
-force in this context includes hidden and system files in the output. ft is short for format table.
If you just need the create timestamp, run Get-ChildItem -force instead.
The following script runs the operation on all files.
$modifyfiles = Get-ChildItem -force | Where-Object {! $_.PSIsContainer}
foreach($object in $modifyfiles)
{
$object.CreationTime=("11/11/2011 12:00:00")
$object.LastAccessTime=("11/11/2011 12:00:00")
$object.LastWritetime=("11/11/2011 12:00:00")
}
只需复制并粘贴,并根据您的要求进行更改。
提示:如果您希望在更改时间戳时使用图形用户界面,请查看自由软件程序Attribute Changer。