在Powershell中一次设置多个属性

Yot*_*ots 5 syntax powershell

是否有一种更短的方法可以在一个命令中将多个属性设置为Powershell中的相同值而不是这个?

例:

(gi  "c:\test.txt").LastWriteTime = (gi  "c:\test.txt").LastAccessTime = (gi  "c:\test.txt").CreationTime = Get-date
Run Code Online (Sandbox Code Playgroud)

我只是好奇是否有办法缩短这种语法.

mjo*_*nor 8

"CreationTime","LastWriteTime","LastAccessTime" |% {(gi test.txt).$_ = (get-date)}
Run Code Online (Sandbox Code Playgroud)

  • 只是为了好玩,你也可以这样做:`$ test.CreationTime,$ test.LastWriteTime,$ test.LastAccessTime = @(get-date)*3 (3认同)