
Powershell を使用してフォルダーを圧縮しようとしましたC:\Program Files
が、次のエラーが発生します。どなたか助けていただけると幸いです。
指示:
powershell.exe -nologo -noprofile -command Compress-Archive -Path "C:\Program Files\avr\cache.dat" -Destinationpath "C:\Program Files\avr\bur\"
エラー:
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
答え1
読んで従ってくださいpowershell /?
(組み込みヘルプ):
-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.
使用
powershell.exe -nologo -noprofile -command "& {Compress-Archive -Path 'C:\Program Files\avr\cache.dat' -Destinationpath 'C:\Program Files\avr\bur\'}"
答え2
コマンドの Powershell 部分は、Powershell インターフェイスでそのまま実行されます。ただし、コマンド プロンプトから実行する場合には、引用符をバックスラッシュでエスケープする必要があります。次のようになります。
powershell.exe -nologo -noprofile -command Compress-Archive -Path \"C:\Program Files\avr\cache.dat\" -Destinationpath \"C:\Program Files\avr\bur\\"