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
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
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 }
Creating zip file using Power shell. first need to install 7Zip software
function create-7zip([String] $aDirectory, [String] $aZipfile){
[string]$pathToZipExe = "$($Env:ProgramFiles)\7-Zip\7z.exe";
[Array]$arguments = "a", "-tzip", "$aZipfile", "$aDirectory", "-r";
& $pathToZipExe $arguments;
}
Remove-item C:\BackupDummy\*.zip
Get-ChildItem C:\Satwadhir\ |
Group-Object -Property { $_.Name.Substring(0, $_.Name.Length) } |
% { create-7zip $_.Group.FullName "C:\BackupDummy\$($_.Name).zip" }