2014-07-05 3 views
1

목표는 다음과 같은 오류를 피하기 위해 특정 파워 쉘 함수로 전달하기 전에 매개 변수가 실행될 수 있는지 확인하는 것입니다Powershell을 사용하여 경로를 실행할 수 있는지 여부를 확인하는 방법은 무엇입니까?

& : The term 'c:\helloworld' 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 C:\functions\function.ps1:67 char:9 
+  & $createServiceCommand install $serviceName 
+   ~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : ObjectNotFound: (c:\helloworld:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

답변

3
if (get-command helloworld -erroraction silentlycontinue) { 
    "Command was found" 
} 
else { 
    "Command was not found" 
} 
+0

'helloworld'를 commandPath로 변경 한 후. 'C : \ Chocolatey \ lib \ chocolatey.0.9.8.24 \ tools \ chocolateyInstall \ NuGet.exe'이 스크립트를 실행하면'Command was found '가됩니다. 이 스크립트를 실행하면'Command was not found '가됩니다. 이 질문에 대한 답변입니다. 고맙습니다. 나는 대답을 받아 들일 것이고 upvote. – 030

-1

당신은 경로의 존재를 확인하기 위해 테스트 경로 cmdlet을 사용할 수 있습니다.

+0

'Test-Path C : \ temp'는 'true'를 나타내며 경로가 존재 함을 나타내지 만 실행 여부를 나타내지 않습니다. – 030

+0

당신이 얻은 오류 메시지를 기반으로, 그 경로가 존재하지 않는다는 것을 의미합니다, 따라서 내 대답. –

관련 문제