powershellazurecompressionazure-functionspowershell-cmdlet

create zip from script location powershell


I have a PowerShell script which should be able to create a zip of a particular folder, which is also in the same location. But the problem is I do not know where this script will be saved. I tried the code below, but I am not able to do it. The Compress-Archieve method shows the argument is null or empty. Please help.

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)

Solution

  • $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