如果我为我的$destination设置了一个数组,我就可以让它工作,但这会为所选的每个目录创建一个独立的.zip。
如何选择每个目录并将它们压缩到单个目标下,而不是多个目标文件?这是我的代码:
$type = "*.txt"
$destination = "LogsBackup.zip"
Add-Type -Assembly "System.IO.Compression.FileSystem" ;
$_sources = dir c:\Logs\$type -Recurse | Select Directory -Unique |
Out-GridView -OutputMode Multiple |
Select @{Name="Path";Expression={$_.Directory -As [string]}}
for ($i = 0; $i -lt $_sources.Length; $i++)
{
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory( $_sources[$i].Path , $destination)
}我希望保留我的Out-GridView选项,所以如果它是一个目录或多个目录,我可以选择它们并将它们存储为一个数组。
发布于 2016-04-01 04:01:51
-update参数将确保使用从out-gridview中选择的新条目更新现有存档。
$destination = "C:\logs\LogsBackup.zip"
#Create a single archive
Get-ChildItem -Path C:\logs -Filter *.txt -Recurse |
Select @{Name="Path";Expression={$_.DirectoryName}} -Unique |
Out-GridView -PassThru | Compress-Archive -CompressionLevel Optimal -DestinationPath $destination -Updatehttps://stackoverflow.com/questions/36324536
复制相似问题