使用 Powershell 获取文件列表 - 在两个日期之间修改

Get List of files Using Powershell - Modified between two dates

我正在使用以下命令获取在 20 小时之前和 20 天之后修改的所有文件..

Get-ChildItem -Path '\server\c$\Program Files (x86)\folder'   -recurse -Filter *.* -include *.* |? {$_.LastWriteTime -lt (Get-Date).Addhours(-20) }|? {$_.LastWriteTime -gt (Get-Date).AddDays(-20)} | Select Fullname ,LASTWRITETIME | Sort-Object -Property LASTWRITETIME -Descending 

它确实给了我正确的结果。

但我得到的全名是:

\server\c$\Program Files (x86...

如何获得全名?全名很长.. 超过 260 个字符.

我试过了

Select -Expand Fullname

它工作正常,但我不能将它与 LastWriteTime 一起使用

Select -Expand Fullname, LastwriteTime 

上面的命令给我错误。

您可以像这样使用 Format-Table cmdlet 格式化输出:

$table_properties = @{Expression={$_.Fullname};Label="Full Name";width=195}, 
                    @{Expression={$_.LastWriteTime};Label="Last Write Time";width=35}

Get-ChildItem -Path '\server\c$\Program Files (x86)\folder'   -recurse -Filter *.* -include *.* |
? {$_.LastWriteTime -lt (Get-Date).Addhours(-20) }|
? {$_.LastWriteTime -gt (Get-Date).AddDays(-20)} | 
Sort-Object -Property LASTWRITETIME -Descending |
Format-Table $table_properties

而不是 Select Fullname,LASTWRITETIME 使用格式化参数创建自定义对象 $table_properties 并将其传递给 Format-Table

如果您的字符串比 PowerShell 主机显示宽度大于管道输出到 Out-String -Width 500,其中 500 个字符足以显示所有字段。

请参阅 TechNet 上的 Creating custom tables 文章。