ひとりになりたい

ノーストレスで生きていく

PowerShellで作成日・更新日を取得・設定する方法

 
Powershellでファイル・フォルダの作成日・更新日を取得・設定する方法について記載します。
 

取得方法

$target_path = 'C:\temp\test_file.txt'
(Get-ItemProperty $target_path).CreationTime
(Get-ItemProperty $target_path).LastWriteTime
 

設定方法

$target_path = 'C:\temp\test_file.txt'
$target_date = '2021/09/12 11:22:33'
Set-ItemProperty $target_path -name CreationTime -value $target_date
Set-ItemProperty $target_path -name LastWriteTime -value $target_date