나는 실행하고자하는 일련의 명령을 가지고 결과에 대한 리턴 코드 검사를하므로 실행을 위해 배열에 넣는 것이 쉽다는 것을 알았습니다.Powershell : 배열의 항목에서 매개 변수가있는 exe를 호출 하시겠습니까?
의 예로 들어이 하나 보자 : 나는 어떤 따옴표없이 내 배열에 넣을 때 지금
C:\windows\system32\inetsrv\AppCmd.exe set config "Default Web Site/" /section system.webServer/webdav/authoring /enabled:true /commit:apphost
을, 그것은 즉시 명령이 실행되는 명령으로 해석이야와 결과는에 기록된다 배열 :
$commands = @()
$commands += C:\windows\system32\inetsrv\AppCmd.exe set config "Default Web Site/" /section system.webServer/webdav/authoring /enabled:true /commit:apphost
따옴표를 사용하여 문자열로 배열에 넣으면 실행하려고 시도하지 않습니다.
PS> $commands = @()
PS> $commands += "C:\windows\system32\inetsrv\AppCmd.exe set config ""Default Web Site/"" /sectio n:system.webServer/webdav/authoring /enabled:true /commit:apphost"
PS> $commands[0]
C:\windows\system32\inetsrv\AppCmd.exe set config "Default Web Site/" /section:system.webServer/webdav/authoring /enabled:true /commit:apphost
PS> & $commands[0]
The term 'C:\windows\system32\inetsrv\AppCmd.exe set config "Default Web Site/" /section:system.webServer/webdav/authoring /enabled:true /commit:apphost' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:2
+ & <<<< $commands[0]
+ CategoryInfo : ObjectNotFound: (C:\windows\syst.../commit:apphost:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
그래서, 내가 어떻게 올바르게 배열, 큐에이 명령을 넣어 않거나 적절한시기에 어떤 가장은 그래서 그것을 실행할 수 있습니다 적합?
아, invoke-expression입니다. 나는 invoke-command를 시도했다. 다음 번에 더 잘 문서를 읽어야합니다. 감사! –