azure 创建zip从脚本位置powershell

wz3gfoph  于 2023-03-24  发布在  Shell
关注(0)|答案(2)|浏览(123)

我有一个PowerShell脚本,它应该能够创建一个特定文件夹的zip,这也是在同一位置。但问题是我不知道这个脚本将保存在哪里。我尝试了下面的代码,但我不能这样做。Compress-Archieve方法显示参数为null或空。请帮助。

Add-Type -AssemblyName System.IO.Compression.FileSystem
$source = Get-ChildItem -Filter -Directory .\PublishOutput
$dest = Get-Location
$f = "\Kovai.zip"
$final = Join-Path $dest $f
Write-Host $final
[System.IO.Compression.ZipFile]::CreateFromDirectory($source,$final)
ctrmrzij

ctrmrzij1#

$folderToZip = "C:\FolderToZip"
$rootfolder = Split-Path -Path $folderToZip
$zipFile = Join-Path -Path $rootfolder -ChildPath "ZippedFile.zip"

Write-Output "folderToZip = $folderToZip"
Write-Output "rootfolder  = $rootfolder"
Write-Output "zipFile     = $zipFile"

Compress-Archive -Path $folderToZip -DestinationPath $zipFile -Verbose

dgsult0t

dgsult0t2#

一个简单的方法来压缩文件夹与子目录

Compress-Archive -PAth test/* -DestinationPath a.zip
 ## replace "test" with your path

相关问题