Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please explain set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) line of Powershell Script

Tags:

powershell

zip

After investigating how to create a zip file with Powershell I found the following very helpful link which describes how to create a zip file using Powershell with the following line of script:

set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))

This works like a charm, problem is I simply don't understand how it works. Could I please get a breakdown of what this does?

like image 740
Sean Hunter Avatar asked Mar 08 '11 09:03

Sean Hunter


1 Answers

By using ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) as the value to set-Content, we are simply adding the file header and creating a 0 byte .zip file.

To understand this, you may want to read under the section file headers:

  • Magic number (programming)
  • ZIP (file format)

Headers in ZIP files begin with "PK" (50 4B), the initials of Phil Katz, author of DOS compression utility PKZIP.

like image 116
ravikanth Avatar answered Sep 19 '22 14:09

ravikanth