Powershell Write-Zip部分文件夹树

mac*_*ack 1 powershell zip pscx

我有一个如下所示的文件夹结构:

-Daily Logs
  -Script1Logs
  -AnotherScriptLogs
  -ThirdScriptLogs
Run Code Online (Sandbox Code Playgroud)

我想压缩"每日日志"下面的所有文件夹,并保留相同的文件夹结构.

有没有办法一次性压缩文件夹而不单独检查每个文件夹?此外,zip文件是否只包含上面显示的文件结构而不是日志文件夹的整个路径?

这是我用来压缩Daily Logs文件夹的内容,但它不压缩子文件夹,它包含每日日志文件夹的完整路径,作为zip文件中文件夹结构的一部分.

If (!(Test-Path $ARCHIVELOGFOLDER\$ARCHIVELOGFILE)) { 
    Write-Zip $file.FullName $ARCHIVELOGFOLDER\$ARCHIVELOGFILE
    Write-Zip -Path $files -OutputPath $ArchiveFile -Append -FlattenPaths -IncludeEmptyDirectories -Quiet -Level 9
} 
Run Code Online (Sandbox Code Playgroud)

Kei*_*ill 5

Write-Zip不是本机PowerShell cmdlet.您正在使用的那个看起来像Oisin编写的PowerShell社区扩展版本.如果像这样使用它将保留路径而不使用完整路径:

C:\InetPub> Write-Zip -Path Logs -OutputPath logs.zip -IncludeEmptyDirectories
Run Code Online (Sandbox Code Playgroud)

请注意,2.1和3.0的最新版本候选中已修复了一些错误.您可以在此处此处获取这些版本.