Unzip a file in PowerShell
Automating configurations on remote machines can sometimes make simple things interesting. In this specific scenario, I needed to use WinRm to Upload a file to a Virtual Machine (VM) on Microsoft Azure. Then I needed to unzip the file and finally go ahead with the configuration of the said software.
Searching the web gave me an appreciable amount of creative ways to go about unzipping files. This was by far the simplest approach I found. Keep in mind that it requires .NET 4.5.
$sourceFile = 'C:\assets\Microsoft.Azure.ServiceFabric.WindowsServer.188.8.131.5294.zip' $targetFolder = 'C:\Microsoft.Azure.ServiceFabric.WindowsServer' [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') [System.IO.Compression.ZipFile]::ExtractToDirectory($sourceFile, $targetFolder)