您可以使用-command参数调用powershell.exe来执行此操作。您也可以使用分号分隔多个powershell命令。你应该双引号加双引号。
下面是一个例子:
powershell -command "$limit = (Get-Date).AddDays(-4); $path = 'T:\Folder Name';Get-ChildItem -Path $path -Recurse -Force -include *.txt | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force"
powershell -command "$limit = (Get-Date).AddDays(-4); $path = 'T:\Folder Name';Get-ChildItem \\123.456.78.910\Y$\Z\*.txt | Where-Object { $_.CreationTime -ge (Get-Date).AddMinutes(-30) } | % { Copy-Item $_.FullName -destination 'T:\DestinationFolderName' }"
编辑: 这里是它的一行版本仅具有单组的“”;所有引号内是单一的“
powershell -command "$limit = (Get-Date).AddDays(-2); $path = 'D:\Folder\Folder Name'; Get-ChildItem -Path $path -Recurse -Force -include *.txt | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force;Get-ChildItem \\123.456.25.123\D$\folder*.txt | Where-Object { $_.CreationTime -ge (Get-Date).AddMinutes(-30) } | % { Copy-Item $_.FullName -destination 'D:\Folder\Folder' }";
检查:http://www.dostips.com/forum/viewtopic.php?f=3&t=5526 – npocmaka 2015-03-25 08:59:51