从Windows命令提示符创build时间戳ZIP存档

我已经做了一个简单的脚本来创build一个使用PowerShell和DOS命令组合的时间戳zip归档,但有没有更好的方法来做到这一点,只需使用pipe道的单个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"