Function to get the path to 7z.exe
function Get-7ZipExecutable { $7zipExecutable = "C:\Program Files\7-Zip\7z.exe" return $7zipExecutable }
Function for zip folders in which the destination is set to
function 7Zip-ZipDirectories { param ( [CmdletBinding()] [Parameter(Mandatory=$true)] [System.IO.DirectoryInfo[]]$include, [Parameter(Mandatory=$true)] [System.IO.FileInfo]$destination ) $7zipExecutable = Get-7ZipExecutable
File decompression function
function 7Zip-Unzip { param ( [CmdletBinding()] [Parameter(Mandatory=$true)] [System.IO.FileInfo]$archive, [Parameter(Mandatory=$true)] [System.IO.DirectoryInfo]$destinationDirectory ) $7zipExecutable = Get-7ZipExecutable $archivePath = $archive.FullName $destinationDirectoryPath = $destinationDirectory.FullName (& $7zipExecutable x "$archivePath" -o"$destinationDirectoryPath" -aoa -r) $7zipExitCode = $LASTEXITCODE if ($7zipExitCode -ne 0) { throw "An error occurred while unzipping [$archivePath] to [$destinationDirectoryPath]. 7Zip Exit Code was [$7zipExitCode]." } return $destinationDirectory }
source share