
<command>
基本的に、PowerShellセッション内で実行されるかのようにPS >
コマンドを渡して、CreateProcess
powershell -Command <command>
上記はすべてのケースで機能するわけではありません。例えば、これは機能しません
powershell -Command gci "C:\Program Files"
しかしこれは機能する
powershell -Command choco -v
答え1
次のようにスクリプトブロック構文powershell
を使用して渡される有効なコマンドを確認します。{}
powershell -Command {gci "C:\Program Files"}
gci C:\Program Files
cmd
通訳は食べる 二重引用符で囲む必要があります。逃げる文字列内のスペースC:\Program Files
、例:
powershell -Command gci "C:\Program` Files" # using backtick
または引用符を使用します (次のコマンド ラインのどれでも機能します):
powershell -Command gci """C:\Program Files""" # inner double quotes
powershell -Command gci "'C:\Program Files'" # inner single quotes
powershell -Command gci 'C:\Program Files' # single quotes