从脚本位置powershell创建zip

时间:2018-01-31 08:06:28

标签: powershell azure compression azure-functions cmdlets

我有一个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)

1 个答案:

答案 0 :(得分:3)

$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

Results