Search code examples
powershellzipcompression

Zip a file on remote server slow, can someone check my PS


Very new here, would anybody check my PS to see if I am compressing 2 files at an optimal rate? It takes seconds when I log on through mstsc, but doing this way is really slow (in the below example, the files are so small, but I want to zip approx 600mb with 2 files):

$compress = @{
  
  Path = "\\servername\c$\Users\Public\Documents\1.txt", "\\servername\c$\Users\Public\Documents\2.txt"
  CompressionLevel = "Fastest"
  DestinationPath = "\\Servername\c$\temp.zip"}
Compress-Archive @compress

Solution

  • Use Invoke-Command to execute Compress-Archive on the remote server (the same way you describe using RDP):

    Invoke-Command -ComputerName Servername {
        $compress = @{
            Path = 'C:\Users\Public\Documents\1.txt','C:\Users\Public\Documents\2.txt'
            CompressionLevel = 'Fastest'
            DestinationPath = 'C:\temp.zip'
        }
        Compress-Archive @compress
    }