Reputation: 65
I've made a simple script to create a timestamped zip archive using a combination of PowerShell and a DOS command, but is there a better way to do this just using a single PowerShell command with piping?
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
Upvotes: 1
Views: 563
Reputation: 52
back.bat:
@echo off
set datetime=%DATE%_%TIME:~-11,2%-%TIME:~-8,2%
set datetime=%datetime:/=-%
tar -acvf "D:\path_%datetime%.rar" "D:\foldername"
Upvotes: 0
Reputation: 28174
You're incredibly close with what you have here. Just drop the get-date
in where you're creating the string for your destination path.
Compress-Archive -Path yourpath -DestinationPath "yourdestpath\yourname-$(get-date -format "{yyyyMMdd-HHmmss}").zip"
Upvotes: 2