Windows zip directory


I am trying to create a zip folder on windows server 2012 r2 using the cookbook whereas my server and workstation are ubuntu based.

When I made my cookbook to run I got the “permission denied” error for creating the zip folder.

I tried giving all 777 mode but no luck.

Please help me out.

Thanks in advance

You may want to take a look at windows_zip file resource:

Unzip a remote zip file locally

windows_zipfile ‘c:/bin’ do
source '
action :unzip
not_if {::File.exists?(‘c:/bin/PsExec.exe’)}end

Unzip a local zipfile

windows_zipfile ‘c:/the_codez’ do
source 'c:/foo/baz/’
action :unzipend

Create a local zipfile

windows_zipfile ‘c:/foo/baz/’ do
source 'c:/the_codez’
action :zipend

Thanks a lot

Since you’re running a cookbook on a Server 2012 R2 machine, and if you have PowerShell 5.0 installed on that server, you could also use powershell_script in your cookbook with PowerShell 5 cmdlets to create a zip/archive:

What resources needs to be used within the recipe?

Can you please show me some example.

Thanks in advance

Your recipe can use the powershell_script resource if you’re running the cookbook on Windows Server. Since your machine is running Server 2012 R2 it will have PowerShell 4.0 by default. However, you can install PowerShell 5.0 if you wish and take advantage of the native cmdlets to compress an archive (zip file).

Here is an example recipe with PowerShell version logic to use the correct PowerShell script based on version:

powershell_script 'create zip file' do
code <<-EOH
If ($host.version.major -ge "5")
  Compress-Archive -Path $Folder -DestinationPath $ZipFile
ElseIf ($host.version.major -ge "3")
  Add-Type -AssemblyName System.IO.Compression.FileSystem
  [System.IO.Compression.ZipFile]::CreateFromDirectory($Folder, $ZipFile)

Also, regarding your “permission denied” problem, you won’t be able to solve it assigning with 777 mode since that command works on Linux machines, not Windows. You’ll need to give the account you’re using on the Windows server proper permissions with Windows commands.

Hope this helps.