Extract Zip files using Powershell Script
Powershell -
Powershell is an awesome task automation and configuration management framework from Microsoft. Powershell is one of the most important tools for System administration task. You can write a number of scripts to automate your task.
In this blog, I'm demonstrating how to Extract ZIP using PowerShell command with 7ZIP.exe extractor.
Prerequisites -
Copy the above script and save it to your local PC as Powershell_Unzip.PS1, change the Zip file location path and destination location path. Once changes are made, execute the script to extract all the zip file into the destination folder.
This script will extract all the files and folders with their name and it's easy to read everything.
Thank you for reading my blog. Please comment down if have any query or want any correction in the script.
Powershell is an awesome task automation and configuration management framework from Microsoft. Powershell is one of the most important tools for System administration task. You can write a number of scripts to automate your task.
In this blog, I'm demonstrating how to Extract ZIP using PowerShell command with 7ZIP.exe extractor.
Prerequisites -
- Installed 7zip.exe
- Few Zip files
Create PowerShell Script -
In order to create a PowerShell script to extract all the zip files that are inside of a folder. Copy this script and paste to Notepad and save it as Powershell_Unzip.PS1
@"
===============================================================================
Title: Extract Zip files
Description: Clean up, Extract Zip file to Destination folder
Requirements: Windows Powershell
Author: Amar Singh
Date: July 23, 2018
===============================================================================
"@
# Allow PowerShell to execute scripts
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
#Create Alias. Make sure you have installed 7Zip.exe in your Windows Machine.
Set-Alias unzip 'C:\Program Files\7-Zip\7z.exe'
#Source path contain Zip files (change it)
$zipfilepath = "D:\testnew\branches"
#Destination Folder to Extract all Zip file and folder (change it)
$Extract_Location = "D:\testnew\clientdata"
#To Clear Destination Folder # Please comment this line if you don't want to clear destination Direcoty
Get-ChildItem $Extract_Location | Remove-Item -Force
#Extract each file using for loop command.
foreach ( $files in $zipfilepath ) {
unzip x -o"$Extract_Location" $zipfilepath
}
exit 0
Copy the above script and save it to your local PC as Powershell_Unzip.PS1, change the Zip file location path and destination location path. Once changes are made, execute the script to extract all the zip file into the destination folder.
This script will extract all the files and folders with their name and it's easy to read everything.
Thank you for reading my blog. Please comment down if have any query or want any correction in the script.