I wasted quite a bit of time trying to find the correct way to zip a folder in PowerShell so that it could later be extracted in a Linux docker container.
TLDR; Turns out the standard unix tar command is now standard-issue in Windows—no need to use PowerShell functions at all.
tar -cvzf myfile.tgz mydir
Microsoft added this in 2017 —nice!
These didn’t work for me:
- PowerShell’s
Compress-Archive
generates Windows path-separators, which Alpine/BusyBox’s version ofunzip
can’t handle (though Debian’sunzip
can). This will be resolved by Microsoft in Version 1.2.3. - The Powershell Community Extensions that includes Gzip and Tar does not currently install cleanly on the most recent PowerShell without this workaround
- I didn’t try GZipStream because I didn’t see an equivalent to
Tar
.
for file in *\\*; do target="${file//\\//}"; mkdir -p "${target%/*}"; mv -v "$file" "$target"; done