Strange behavior of some zip files while extracting (7zip) - powershell

I have a problem with unzipping files. Usually I use a PowerShell script, that I run through SQL Server database (procedure) and it will unzip my files how I want them (database shouldn't be any issue).
Main part of script:
exec '"for %i in ("'+#path+'\*.zip") do "C:\Program Files\7-Zip\7z.exe" x "%i" -o"'+#to+'""'
But for once in a while there is a .zip file that if run through this script will extract files with names of files encoded badly and to prevent that I need to manually open every .zip file and click to extract in 7-zip GUI and that will returns names of files correctly.
This manual way of doing things very, very slow. Because it needs to be done on a server, God forbids if I am on VPN at home. So let's say I have 5 zip files (3 GB), it will take me hours to unzip. If I do it, through server it takes like 2 minutes.
So I just trying to find out how to unzip it with script, what is the difference between my script and manual extraction?

The root-cause is likely to be files that were created with a setup that doesn't match the codepage of your windows environment. Are any of the zip file publicly available? If so, can you provide a link?
To deal with these problem files, you need to know what encoding was used for the filenames. If the 7z gui can handle these files automatically there must be an option to tell it what encoding to use.
Once you know the encoding you can use the -scs option in 7z to decode the filenames correctly.
Modern zip files don't have this issue because they store filenames in UTF-8.

Related

When to use pg_dump output in script or archive file format?

I am starting to learn about databases and I have seen in the documentation (https://www.postgresql.org/docs/current/app-pgdump.html) that I can have an output of the pg_dump in either script or archive file format.
My question is, why would I choose an archive over a script format and another way around?
Is it only about the fact, that with archive files I can choose which part of the database should be restored with pg_restore? And if archive format seems to be more flexible than script format why would I ever choose to use script files instead?

Unzip a file from several large compressed folder from command line

I have several large zipped folders in my cloud storage drive. I want to transfer a specific file from each of the zipped folders to my local hard drive (I cant copy all of them since i dont have enough space). Is there a way to do this using command line/cmd or powershell. I am using Windows 10 (Build 18362).
The file name is the same so i was hoping if i can write a loop to do this.

Convert a PowerShell script to exe Including an Exe file into it

I have a few Powershell scripts that I use to copy files and run installations with the required install steps included in the sript, i know how to convert these scripts into exes. I would like to know, how to include the files I am installing with the script in the powershell converted exe?
This utility on github has proven very useful to me:
https://github.com/rzander/PS2EXE
It comes with a pretty straightforward GUI and command-line version, but only works with one PowerShell file.
I have modified a personal version to take multiple files and combine them into one executable. Let me know if you’re interested and I can upload it.
I would like to answer my own question for whom ever come across the same issue or need!
I had the way of doing this all along, but I didn't pay attention to details: For what I required which is to convert a .PS1 script that installs postgresql unattended, to an .exe file including(Postgres enbedded in the exe).
The best tool for this is the "PS1 to EXE" https://gallery.technet.microsoft.com/PS1-To-EXE-Generator-d39e8be2 software,
1. Load your ps1 file, make sure everything is working before hand.
2. Embed the the files you need for the ps1 to work (embed option is on the right column next to the "Options")
Then you can click the convert option
PS: Be sure to have the correct file path.

How do I make a tarball with winrar from command line

This should be straight forward like it is with 7-zip, but it's not and google is not helping.
I'm doing the following at the command line
rar a -ep1 "C:\Mail\test.zip" "C:\Mail\LastEmail.txt"
and it keeps creating "test.zip" in rar archive format. It needs to be in zip format.
Ultimately I want to make a .tar.gz file.
The text file Rar.txt is the user's manual for console version Rar.exe.
The second and third paragraph in Introduction chapter at top of this file are:
RAR supports only RAR format archives, which have .rar file name extension by default. ZIP and other formats are not supported. Even if you specify .zip extension when creating an archive, it will still be in RAR format. Windows users may install WinRAR, which supports more archive types including RAR and ZIP formats.
WinRAR provides both graphical user interface and command line mode. While console RAR and GUI WinRAR have the similar command line syntax, some differences exist. So it is recommended to use this rar.txt manual for console RAR (rar.exe in case of Windows version) and winrar.chm WinRAR help file for GUI WinRAR (winrar.exe).
This is also true for free UnRAR.exe which is also a console application.
WinRAR.chm contains help of WinRAR.exe. On tab Contents there is the list item Command line mode with the Command line syntax page and the lists Commands and Switches. The page about switch -af<type> - specify archive format explains the difference that WinRAR.exe supports compressing and uncompressing ZIP archives with or without using this switch while console version Rar.exe does not support ZIP archives.

Locate Compressed files on servers

I would like to create a powershell script generating a report showing all compressed files/folders on remote servers. By compressed files I mean files compressed using the buildin Windows Compression utility, not zip. But I have a hard time figuring out how to localize the compressed files. Should I go with WMI or?
Thanks
Frank
The FileInfo/DirectoryInfo classes from .NET (I assume all of this is easy available to PowerShell) will give you the file attributes that includes the compression attribute if compressed.