1、多个单独文件压缩成zip
Param(
[string]$sourcePath = ".", # 指定源目录,默认为当前目录
[string]$destinationPath = "." # 指定目标目录,默认为当前目录
)
$folders = Get-ChildItem -Path $sourcePath -Directory
foreach ($folder in $folders) {
$folderName = $folder.Name
$zipFileName = "$destinationPath\$folderName.zip"
Write-Host "Creating archive $zipFileName"
Compress-Archive -Path $folder.FullName -DestinationPath $zipFileName -CompressionLevel Fastest
}
2、解压多个zip文件成单独的文件
$sourceFolder ="E:\22" #zip压缩包路径
$destinationFolder = "E:\22" #解压后路径
Get-ChildItem -Path $sourceFolder -Filter *.zip | ForEach-Object {
$zipFile = $_.FullName
$extractPath = Join-Path $destinationFolder $_.BaseName
Expand-Archive -LiteralPath $zipFile -DestinationPath $extractPath
}