-1

I am writing a powershell script to create a zip folder on the remote machine of size 47 gb in the C:\ drive . The folder is also in C:\ drive . The C:\ drive have 66gb free space but still gives me error of "not enough memory resources" to create the zip so I tried to create the zip from C:\ to H:. My H:\ drive have 121 gb free but still is giving me error. I am attaching the screenshot of both errors.

enter image description here

$curentDirectory = $PSScriptRoot
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
            Write-Output "Script Current Directory is:"$curentDirectory
            Write-Output "Reading Configuration From :"$curentDirectory"/config.xml"

            $myData = [xml](Get-Content $curentDirectory"/config.xml" -ErrorAction Stop)
            $machineName = $myData.'tangoEnvironment'.VM01.machineName
            $machineDrive= $myData.'tangoEnvironment'.VM01.machineDrive
            $remoteUser = $myData.'tangoEnvironment'.VM01.remoteUser
            $remotePassword = $myData.'tangoEnvironment'.VM01.remotePassword
            $userCred     =     New-Object Management.Automation.PSCredential($remoteUser, (convertto- 
                    securestring $remotePassword -asplaintext -force))
                    Invoke-Command -ComputerName $machineName -Credential $userCred -ScriptBlock {
                        
                        Write-Host    ""   
                        Write-Host     "Response from Jump Server($env:COMPUTERNAME) ..."
                        # Rest of service
                        Compress-Archive -Path C:/Humera -DestinationPath H:"/Humera.zip" 
                        
                    }

   cmd /c pause
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • 1
    ZIP has limitations regarding the size of archive and files inside archive. Try to use 7-zip instead. – zett42 Feb 19 '21 at 11:16
  • 1
    Disk space is not the issue here. `Invoke-Command` means the code is running in a remote shell, and there will be a limit to how much memory (RAM, not disk space) that the shell can allocate. – Mathias R. Jessen Feb 19 '21 at 11:31
  • Welcome to Stack Overflow. In addition to both valid points above, ZIP works in a work area, and writes its output based on that work area. In some cases it will need at least 100% extra space in order to achieve its goal. – Dennis Feb 19 '21 at 16:33

1 Answers1

1

Powershell remote sessions have a small memory limit - see the answers to this question:

From: http://msdn.microsoft.com/en-us/library/windows/desktop/aa384372(v=vs.85).aspx - The defult memory limit on remote shells is 150MB

To resolve, this can be increased:

Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000000
Set-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB 1000000
Restart-Service WinRM

But Compress-Archive also has a size limit!

The Compress-Archive cmdlet uses the Microsoft .NET API System.IO.Compression.ZipArchive to compress files. The maximum file size is 2 GB because there's a limitation of the underlying API.

You will need to use a third-party utility like 7zip to compress a single file that large.

Cpt.Whale
  • 4,784
  • 1
  • 10
  • 16