为什么出现以下错误:“ MissingVariableNameAfterForeach”:
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "foreach($file in Get-ChildItem C:){((Get-Date)-$file.LastWriteTime).ToString('dd')}"
该命令应该打印出从今天开始在C:\中写入最后一个文件/文件夹的日期。
从帮助文本:
PS C:\> powershell.exe /?
If the value of Command is a script block, the script block must be enclosed in braces ({}). You can specify a script block only when running PowerShell.exe in Windows PowerShell.
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command {Get-ChildItem C: | ForEach-Object{($_.LastWriteTime).ToString('dd')}}