Uso de Powershell Compress-Archive para carpetas en C:\Program Files

Uso de Powershell Compress-Archive para carpetas en C:\Program Files

Al intentar comprimir una carpeta usando C:\Program FilesPowershell, aparece el siguiente error. Agradezco si alguien puede ayudar.

Dominio:

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

Error:

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

Respuesta1

Leer y seguir powershell /?(ayuda integrada):

-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.

Usar

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

Respuesta2

La parte de Powershell de su comando se ejecutará tal cual en la interfaz de Powershell. Pero si lo ejecuta desde un símbolo del sistema, debe evitar las comillas con barras invertidas. Como esto:

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

información relacionada