2017-12-14 17 views
0

명령에서 따옴표로 변수를 사용하여 - Start-Process 부분에 집중 :파워 쉘 (이것은 다음과 같이 정확하게, 삼중 따옴표가 실수없는 작품) 나는 어떤 작품이이

Start-Process powershell -Credential $cred -WorkingDirectory "$lettre_disque" -ArgumentList '-noprofile -command &{Start-Process """D:\WD Drive Unlock.exe""" -verb runas}' 

지금 나는 단순히 해요

"""$chemin_fichier""" 

""$chemin_fichier"" 

"$chemin_fichier" 

""""$chemin_fichier"""" 
: 내가 노력하고있어 동일한 텍스트 ( D:\WD Drive Unlock.exe)

을 포함 $chemin_fichier라는 이름의 변수로 문자열 D:\WD Drive Unlock.exe을 대체하려고

아무 것도 작동하지 않습니다 ...

어떻게 표시 되나요? 이 명령은 매우 혼란 스럽습니다. 올바른 조합은 무엇입니까? 나는 무엇인가를 벗어나야 만합니까?

도움을 주셔서 감사합니다.

+0

-ArgumentList ('-noprofile -command & {시작 프로세스 ""D : \ WD 드라이브 Unlock.exe ""-verb runas} "-f $ chemin_fichier – EBGreen

+0

내 목표는 D : \ WD를 제거하는 것입니다. ... 편지가 변수이기 때문에 올바른 경로가 $ chemin_fichier에 저장됩니다. 어떻게 문자열을 대체 할 수 있도록 $ chemin_fichier를 배치합니까? 예 : -ArgumentList ('-noprofile -command & {Start-Process "" "$ chemin_fichier" "" – Rakha

+1

Wooops ... 편집을 마쳤습니다. \t -ArgumentList ('-noprofile -command & 프로세스 "" "{0}" ""-verb runas} '-f $ chemin_fichier) – EBGreen

답변

1

내가 스플래를 사용하여 조각으로 명령을 깰 것 :

$chemin_fichier = 'D:\WD Drive Unlock.exe' 

$ArgList = @{ 
    FilePath = 'powershell' 
    Credential = $cred 
    WorkingDirectory = $lettre_disque 
    ArgumentList = @(
     '-NoProfile' 
     '-Command' 
     "`"Start-Process -FilePath '$chemin_fichier' -Verb runas`"" 
    ) 
} 
Start-Process @ArgList 

스크립트 블록에 명령을 포장이 필요했다.

+0

고맙습니다. 그렇습니다. 한 줄 명령으로 작업하는 악몽이었습니다. 하하는 구문이 하드 코어입니다. 언젠가 그것까지 어느 정도 감사하겠습니다. – Rakha

+1

@Rakha Yeah,'Start-Process' 논쟁은 처음에는 힘들었습니다. – TheIncorrigible1