With the July release of PowerShell V5 Preview (Download links are 1/3 of the way down on the DSC download page), there are some new things that have been added that are worth talking about.
Here are the direct download links for the July Preview of PowerShell V5:
- X64 http://download.microsoft.com/download/E/D/B/EDB86AD9-4D26-4C33-A8B2-82BE161682E2/WindowsBlue-KB2969050-x64.msu
- X86 http://download.microsoft.com/download/E/D/B/EDB86AD9-4D26-4C33-A8B2-82BE161682E2/WindowsBlue-KB2969050-x86.msu
If you recall, I talked about some of the new things in PowerShell V5 Preview here and here but now I am going to go over one of the new items that have been added to this release:
Finally we have cmdlets which allow us to create a zip archive to zip and unzip files.
From what we can see with the help file on Compress-Archive, there are 2 parameter sets that are based on Path and LiteralPath parameters. We have an –Update parameter which allows us to add to an existing archive file. We can also set the CompressionLevel (Fastest, NoCompression or Optimal (Default Value)) for the archive.
Let’s give it a quick run to see what happens:
Get-ChildItem | Compress-Archive -DestinationPath 'C:\users\boe.prox\Desktop\Archive.zip' -Verbose
Note: Using just a folder without a full path name causes the script to throw errors
It still creates an archive, but it seems to move it to the parent folder above my current path. It probably should just use the current path if none is given.
This feels like a bug to me and should handle the current directory instead of shipping it somewhere else and throwing errors. If you think so to, feel free to vote this up: https://connect.microsoft.com/PowerShell/feedbackdetail/view/954121/v5-july-preview-compress-archive-should-default-to-current-directory-if-fully-qualified-path-given-for-destination-path
If you don’t use the –Update parameter and try to add something to an existing archive, an error will be thrown reminding you to use –Update.
Pretty much all there is to that. Now let’s check out the second cmdlet for archives.
Again, we have 2 parameter sets for Path and LiteralPath. We just have to supply the archive file and a destination path for the archive folder. What I am curious to see is if I do not supply a DestinationPath which requires a folder name and if the folder that everything is unzipped to will be the name of the archive.
Expand-Archive .\Archive.zip -DestinationPath $Pwd -Verbose
It appears that it will not create a folder based on the archive name and will instead attempt to unzip the file to the existing directory. If the file exists, you will see errors stating to use the –Force parameter, which makes sense.
Now lets run this and specify an actual folder name (but one that doesn’t exist).
Expand-Archive .\Archive.zip -DestinationPath 'UnzippedArchive' -Verbose
Well, it didn’t like that at all. I guess we have to specify an existing folder in order for this to work. At first I wasn’t sure how I liked that, but copy-item and move-item do not auto create directories if they do not exist, so I would expect this cmdlet to do the same.
Well, that is it for checking out the new cmdlets: Compress-Archive and Expand-Archive! I will look to dive into another new addition to PowerShell V5 July Release in the coming days. Stay tuned!
Pingback: ZIP Kompression mit der PowerShell; eine Übersicht. › Windows PowerShell Community
This is sweet.
Oh this is sweet.
I don’t see a link on to PowerShell V5 July Release. Can you provide a working URL?
I have a link at the top of the blog article that goes to the DSC page which has the direct download links. I’ll update this article to point to the direct download links tonight.
It’s been updated with the direct download links.