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:
Archive Cmdlets
Finally we have cmdlets which allow us to create a zip archive to zip and unzip files.
- Compress-Archive
Image may be NSFW.
Clik here to view.
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
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Note: Using just a folder without a full path name causes the script to throw errors
Image may be NSFW.
Clik here to view.
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.
Image may be NSFW.
Clik here to view.
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.
Image may be NSFW.
Clik here to view.
Pretty much all there is to that. Now let’s check out the second cmdlet for archives.
- Expand-Archive
Image may be NSFW.
Clik here to view.
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
Image may be NSFW.
Clik here to view.
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
Image may be NSFW.
Clik here to view.
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.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
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!
Filed under: powershell Tagged: archive, Compress, Expand, Powershell, v5, WhatsNew, zip Image may be NSFW.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
