Archive for March, 2023

UnGzip-File function added to AZSBTools PowerShell module to decompress GZip files in Windows


Microsoft provides the Expand-Archive cmdlet as part of the Microsoft.PowerShell.Archive module to decompress ZIP files in Windows. However, there’s no native cmdlet to decompress GZip files.

This new function of the AZSBTools module leverages native .Net 2.0 libraries to decompress GZip files in Windows.

The function’s built in help can be shown using

help UnGZip-File -ShowWindow

Here’s a demo of using this function:

# Demo UnZip-File

# Input
$FolderPath = 'c:\Sandbox\pfSense'
$URL        = 'https://atxfiles.netgate.com/mirror/downloads/pfSense-CE-2.6.0-RELEASE-amd64.iso.gz'

# Download the GZ file into the $FolderPath
$GZFilePath = Join-Path $FolderPath (Split-Path $URL -Leaf) # Concatenate the $FolderPath with the file name
Invoke-WebRequest -Uri $URL -OutFile $GZFilePath

# Decompress the GZ (GZIP) file using the new UnGzip-File function
UnGZip-File -GzFile $GZFilePath -OutFile ($GZFilePath -replace '.gz','') -ShowProgress

In the PowerShell ISE, you should see the download progress like:

Followed by the decompression progress like:

Warning:

Using the -ShowProgress switch will SIGNIFICANTLY slow down the decompression process. It is not recommended to use this switch with large files.

At the end, the function displays decompression stats to the console like:

The same can be seen in Windows Explorer:


To use/update the AZSBTools PowerShell module which is available in the PowerShell Gallery, you can use the following code:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted 
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 
# PowerShellGallery dropped Ssl3 and Tls as of 1 April 2020
Remove-Module AZSBTools -Force -EA 0 
Install-Module AZSBTools -Force -AllowClobber -SkipPublisherCheck # -Scope CurrentUser
Import-Module AZSBTools -DisableNameChecking -Force 
Get-Command -Module AZSBTools

You need PowerShell 5. To view your PowerShell version, in an elevated PowerShell ISE window type

$PSVersionTable

To download and install the latest version of AZSBTools from the PowerShell Gallery and its dependencies, type

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

To trust the Microsoft PowerShell Gallery repository, then

Install-Module AZSBTools,Az -Force -AllowClobber -Scope CurrentUser

AZSBTools contains functions that depend on Az module, and they’re typically installed together.

To load the AZSBTools, and Az modules type:

Import-Module AZSBTools,Az -DisableNameChecking

To view a list of cmdlets/functions in AZSBTools, type

Get-Command -Module AZSBTools

To view the built-in help of one of the AZSBTools functions/cmdlets, type

help <function/cmdlet name> -show

such as

help Get-DayOfMonth -show