How to set LastWriteTime property of a file?

有些话、适合烂在心里 提交于 2019-12-05 18:28:45

Not tested, but try this in your loop after you call New-Item:

$file = Get-ChildItem $path$clientname$space$date$space$time.bak
$file.LastWriteTime = (Get-Date).AddDays(-1-$i)

If you want to see a full listing of things you can do with FileInfo objects, try calling $file | gm in your powershell console. You could also view the docs on MSDN.

for ($i=0; $i -lt 7;$i++)
{
     $date = (Get-Date).AddDays(-1-$i)
     $filedate = $date.ToString('yyyy-MM-dd') 
     $file = New-Item -ItemType File $path$clientname$space$filedate$space$time.bak
     $file.LastWriteTime = $date
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!