Quantcast
Channel: Spiceworks Community
Viewing all articles
Browse latest Browse all 7

Powershell, 7-zip, Password protected zip

$
0
0

I have a powershell script which runs a SQL query, dumps the results into a CSV, then converts it to Excel format. I then need to create a password protected zip file containing that .xls file.

I couldn't find a way to do this natively in Powershell. I've seen a few functions and add-ons to install, etc., but nothing built in.

So I decided to just use 7-zip.

From a regular command line, this command works just fine:

"c:\Program Files\7-Zip\7z.exe" a c:\temp\testfile.zip c:\temp\*.xls -pTough.Pass-word

The first thing I stumbled on in Powershell was the spaces in the 7z command line. So I created an alias, and now have this:

set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"

sza c:\temp\testfile.zip c:\temp\*.xls -pTough.Pass-word

When I try to run my script I get this:

C:\>sqlps u:\scripts\DumpDocketToExcel.ps1
What is the...

This topic first appeared in the Spiceworks Community

Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>