Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Syntax 在Powershell中同时设置多个属性_Syntax_Powershell - Fatal编程技术网

Syntax 在Powershell中同时设置多个属性

Syntax 在Powershell中同时设置多个属性,syntax,powershell,Syntax,Powershell,在一个命令中将Powershell中的多个属性设置为相同值的方法是否比此短 例如: (gi "c:\test.txt").LastWriteTime = (gi "c:\test.txt").LastAccessTime = (gi "c:\test.txt").CreationTime = Get-date 我只是好奇是否有办法缩短这种语法。“CreationTime”、“LastWriteTime”、“LastAccessTime”|%{(gi test.txt)。$\u=(get

在一个命令中将Powershell中的多个属性设置为相同值的方法是否比此短

例如:

(gi  "c:\test.txt").LastWriteTime = (gi  "c:\test.txt").LastAccessTime = (gi  "c:\test.txt").CreationTime = Get-date
我只是好奇是否有办法缩短这种语法。

“CreationTime”、“LastWriteTime”、“LastAccessTime”|%{(gi test.txt)。$\u=(get date)}
我使用了Mjolinor答案的一个稍加修改的版本来解决我刚刚从远程源下载的文件日期不正确的问题。我对代码进行了修改,使其更清晰易懂,以防将来不得不返回(将缩写改为完整的命令名)

#正确访问/创建/写入传输文件的时间
ForEach($TransferList中的文件){
@(“CreationTime”、“LastAccessTime”、“LastWriteTime”)ForEach{
$(获取项$File.Name)。$\ux=$File.Date
}
}

为了好玩,您也可以这样做:
$test.CreationTime,$test.LastWriteTime,$test.LastAccessTime=@(获取日期)*3
您的两个答案在语义上与op的示例不太一样。所有三个道具上的OP保证日期相同。在你的情况下,不是这样。foreach对象和*乘数都有可能发生翻滚。