我可能已经理解了您的问题,因为现有的答案似乎没有提供我认为您正在寻找的信息。
虽然这些示例并未具体回答您在标题中提出的问题,但它们旨在输出我认为您正在寻找的内容。
因此,这是我的batch-file 尝试:
@"%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile -Command^
"Get-ChildItem -Path 'C:\'|Sort-Object -Property LastWriteTime|"^
"Select-Object -Last 1|Format-Table -AutoSize -Property Name,"^
"@{Name='DaysOld';Expression={[Int]$((Get-Date)-$_.LastWriteTime).TotalDays}}"
@Pause
显然是cmd 版本,成为话题:
"%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile -Command "Get-ChildItem -Path 'C:\'|Sort-Object -Property LastWriteTime|Select-Object -Last 1|Format-Table -AutoSize -Property Name,@{Name='DaysOld';Expression={[Int]$((Get-Date)-$_.LastWriteTime).TotalDays}}"
以防万一这只是我的误解,也许这个
batch-file 可能对你有用:
@"%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile -Command^
"Get-ChildItem -Path 'C:\'|Sort-Object -Property LastWriteTime -Descending|"^
"Format-Table -AutoSize -Property Name,"^
"@{Name='DayInMonth';Expression={($_.LastWriteTime).ToString('dd')}},"^
"@{Name='DaysOld';Expression={[Int]$((Get-Date)-$_.LastWriteTime).TotalDays}}"
@Pause
cmd版本:
"%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile -Command "Get-ChildItem -Path 'C:\'|Sort-Object -Property LastWriteTime -Descending|Format-Table -AutoSize -Property Name,@{Name='DayInMonth';Expression={($_.LastWriteTime).ToString('dd')}},@{Name='DaysOld';Expression={[Int]$((Get-Date)-$_.LastWriteTime).TotalDays}}"
在这两种情况下,您都会注意到,因为我没有运行 PowerShell 脚本,因此无需规定执行策略。命令应该像直接在 PowerShell 窗口中运行一样工作。