Home > Back-end >  Using PowerShell to Create Zip Files
Using PowerShell to Create Zip Files

Time:02-24

I have a folder with files. I need to filter according to an extension and to ZIP one by one

$files = Get-ChildItem -path "C:\Temp\SharedFolder\SideVIP\*" -Filter *.VIP
foreach ($file in $files) {

Need some help with the rest

CodePudding user response:

In PowerShell 4 , you can use Compress-Archive

$destPath = 'X:\NewPath'
foreach($file in $files) {
  Compress-Archive -Path $file -DestinationPath "$destPath\$($file.BaseName).zip" 
}

And if you need to "unzip":

$files = Get-ChildItem C:\Temp\SharedFolder\SideVIP\*.zip
foreach($file in $files) { Expand-Archive -Path $file -DestinationPath . -Force }
  • Related