我正在尝试将文件创建日期放入powershell中的一个变量中,但是无法做到这一点。"$_.CreationTime“只打印字符串字面".CreationTime”。如何获得文件的实际创建时间?
$builds = Get-ChildItem "$path_to_directory" *.zip | Where-Object {$_.CreationTime -gt $lastBuildDeployedTimestamp}
foreach($build in $builds)
{
"$path_to_directory"
"$_.CreationTime"
}
发布于 2022-07-23 09:59:04
使用"$($_.CreationTime)“。
在您的特定示例中,应该是"$($build.CreationTime)“
发布于 2022-07-23 10:06:16
一个班轮方法是Get-ChildItem $path_to_directory *.zip | Where-Object {$_.CreationTime -gt $lastBuildDeployedTimestamp} | Select-Object -Property FullName, CreationTime
。
但是,如果希望保留循环,则需要使用$build
。
$builds = Get-ChildItem $path_to_directory *.zip | Where-Object {$_.CreationTime -gt $lastBuildDeployedTimestamp}
foreach($build in $builds)
{
$path_to_directory
$build.CreationTime
}
有关更多信息,请参见Get-Help about_Foreach -Full
https://stackoverflow.com/questions/73089435
复制相似问题