Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Windows命令提示符创建带时间戳的ZIP存档_Windows_Powershell_Command Line - Fatal编程技术网

从Windows命令提示符创建带时间戳的ZIP存档

从Windows命令提示符创建带时间戳的ZIP存档,windows,powershell,command-line,Windows,Powershell,Command Line,我已经编写了一个简单的脚本,可以使用PowerShell和DOS命令的组合创建一个带时间戳的zip存档,但是有没有更好的方法,只使用一个带管道的PowerShell命令 FOR /F "tokens=* USEBACKQ" %%F IN (`powershell get-date -format "{yyyymmdd-HHmmss}"`) DO ( SET ARCHTIMESTAMP=%%F ) powershell Compress-Archive -Path yourpath -Desti

我已经编写了一个简单的脚本,可以使用PowerShell和DOS命令的组合创建一个带时间戳的zip存档,但是有没有更好的方法,只使用一个带管道的PowerShell命令

FOR /F "tokens=* USEBACKQ" %%F IN (`powershell get-date -format "{yyyymmdd-HHmmss}"`) DO (
SET ARCHTIMESTAMP=%%F
)

powershell Compress-Archive -Path yourpath -DestinationPath yourdestpath\yourname-%ARCHTIMESTAMP%.zip

你和这里的情况非常接近。只需将
get date
放在为目标路径创建字符串的位置

Compress-Archive -Path yourpath -DestinationPath "yourdestpath\yourname-$(get-date -format "{yyyyMMdd-HHmmss}").zip"

欢迎来到卡宁。当然,纯粹在PowerShell中有一种更简单的方法可以做到这一点。您希望使用管道或在单个命令中执行此操作有什么特殊原因吗?或者您只是在寻找一种更干净的方式来表达这一点?我只是在寻找一种更干净的解决方案,因为它感觉有点笨重。谢谢,这在其他一些方面也会有所帮助!我做了一个小编辑,月份占位符是大写的MM,小写的MM是分钟。