Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 425 Vote(s) - 3.59 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running 7-Zip from within a Powershell script

#1
I'm trying to use 7-Zip to backup some files inside a Powershell (v2) script.

I have:

$zipPath = "C:\Program Files\7-Zip\7z.exe"
[Array]$zipArgs = "-mx=9 a", "`"c:\BackupFolder\backup.zip`"", "`"c:\BackupFrom\backMeUp.txt`""

&$zipPath $zipArgs;

But when I run this I get:

7-Zip [64] 9.20 Copyright © 1999-2010 Igor Pavlov 2010-11-18


Error:
Incorrect command line

Writing this to the screen I get:

C:\Program Files\7-Zip\7z.exe -mx=9 a "c:\BackupFolder\backup.zip" "c:\BackupFrom\backMeUp.txt"

So I assumed that I needed to put quotes around the path to 7z.exe, that gave me:

$zipPath = "C:\Program Files\7-Zip\7z.exe"
$zipPath = " `"$zipPath`" "
[Array]$zipArgs = "-mx=9 a", "`"c:\BackupFolder\backup.zip`"", "`"c:\BackupFrom\backMeUp.txt`""

&$zipPath $zipArgs;

But then I get the following error:

The term '"C:\Program Files\7-Zip\7z.exe"' is not recognized as the name of a cmdlet, function, script file
, or operable program. Check the spelling of the name, or if a path was included, verify that the path is c
orrect and try again.
At C:\BackupScript\Backup.ps1:45 char:22
+ & <<<< `"$zipPath`" $zipArgs;
+ CategoryInfo : ObjectNotFound: ("C:\Program Files\7-Zip\7z.exe":String) [], CommandNotFound
Exception
+ FullyQualifiedErrorId : CommandNotFoundException

Writing it out gives me:

"C:\Program Files\7-Zip\7z.exe" -mx=9 a "c:\BackupFolder\backup.zip" "c:\BackupFrom\backMeUp.txt"


Which works as expected when pasting straight into a command window.
I have been trying to figure this out for a while, but assume I am missing something (probably quite obvious). Can anybody see what I need to do to make this run?
Reply

#2
Maybe a simpler solution is to run 7-zip on your Powershell via `cmd`:

cmd /c 7za ...
Reply

#3
put "&" special character before 7z command. Example: &7z ...
Reply

#4
try to use parameter -file to specify the location of program or script:

-file "C:\Program Files\someting.exe"

Reply

#5
Simply prefix the command with an ampersand

& "C:\Program Files\7-Zip\7z.exe" -mx=9 a "c:\BackupFolder\backup.zip" "c:\BackupFrom\backMeUp.txt"
Reply

#6
If you adapt it correctly: Dont forget the "" on "$Target"
and avoid $7zipPath in c:\programm files with a space in the path

Set-Alias 7zip $7zipPath

$Source = "c:\BackupFrom\backMeUp.txt"
$Target = "c:\BackupFolder\backup.zip"

7zip a -mx=9 "$Target" "$Source"

or

7z a "$ArchiveName" -t7z '@listfile.txt'

Reply

#7
C:\'Program files'\7-Zip\7z.exe a '$archiveFile' -Path '$dest'

where:

* `archiveFile` = name of the archive file name.
* `dest` = destination folder.
Reply

#8
Found [this][1] script and adapted it to your needs. Can you please try:

```powershell
$7zipPath = "$env:ProgramFiles\7-Zip\7z.exe"

if (-not (Test-Path -Path $7zipPath -PathType Leaf)) {
throw "7 zip file '$7zipPath' not found"
}

Set-Alias Start-SevenZip $7zipPath

$Source = "c:\BackupFrom\backMeUp.txt"
$Target = "c:\BackupFolder\backup.zip"

Start-SevenZip a -mx=9 $Target $Source
```

[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through