Powershell REPL 내에서 실행된 것처럼 staement를 실행하는 방법

Powershell REPL 내에서 실행된 것처럼 staement를 실행하는 방법

<command>기본적으로 나는 명령이 powershell 세션 내에서 실행된 것처럼 PS >호출되도록 전달하고 싶습니다 .CreateProcess

powershell -Command <command>

위의 내용은 모든 경우에 작동하지 않습니다. 예를 들어, 이것은 작동하지 않습니다

powershell -Command gci "C:\Program Files"

하지만 이건 효과가 있어

powershell -Command choco -v

답변1

다음과 같이 scriptblock 구문을 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

관련 정보