Verwenden von Powershell Compress-Archive für Ordner in C:\Program Files

Verwenden von Powershell Compress-Archive für Ordner in C:\Program Files

Beim Versuch, einen Ordner mit Powershell zu komprimieren, C:\Program Fileswird jedoch der folgende Fehler angezeigt. Ich bin dankbar, wenn mir jemand helfen kann.

Befehl:

powershell.exe -nologo -noprofile -command Compress-Archive -Path "C:\Program Files\avr\cache.dat" -Destinationpath "C:\Program Files\avr\bur\"

Fehler:

Compress-Archive : A positional parameter cannot be found that accepts argument 'Files\avr\cache.dat'.
At line:1 char:1
+ Compress-Archive -Path C:\Program Files\avr\cache.dat -Destina ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo         : InvalidArgument: (:) [Compress-Archive], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Compress-Archive

Antwort1

Lesen und befolgen Sie powershell /?(integrierte Hilfe):

-Command
To write a string that runs a Windows PowerShell command, use the format:
    "& {<command>}"
where the quotation marks indicate a string and the invoke operator (&)
causes the command to be executed.

Verwenden

powershell.exe -nologo -noprofile -command "& {Compress-Archive -Path 'C:\Program Files\avr\cache.dat' -Destinationpath 'C:\Program Files\avr\bur\'}"

Antwort2

Der Powershell-Teil Ihres Befehls wird in der Powershell-Oberfläche so ausgeführt, wie er ist. Wenn Sie ihn jedoch von einer Eingabeaufforderung aus ausführen, müssen Sie die Anführungszeichen mit Backslashs maskieren. So:

powershell.exe -nologo -noprofile -command Compress-Archive -Path \"C:\Program Files\avr\cache.dat\" -Destinationpath \"C:\Program Files\avr\bur\\"

verwandte Informationen