从脚本位置 powershell 创建 zip

create zip from script location powershell

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