2016-10-26 6 views
1

ineracvie powershell에서 무언가를하려고하면 speific 오류를 잡을 수 있습니까? 말 :인터랙티브 파워 쉘에서 캐치 오류

powershell.exe 
PS C:>_ 
PS C:>fuu 
fuu: this is not a cmdlet .... BLA BLA BLA 
+ ~~~ 
    + CategoryInfo   : ObjectNotFound: (fuu:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

이 ineractive 파워 쉘의 정상적인 동작입니다. 내 Profile.ps1에 뭔가를 넣을 수 있습니까? 예를 들어 이러한 CommandNotFoundException과 같이 특정 오류가 발생했을 때도 모든 것이 그대로 유지 될 수 있습니까?이 오류에서만 powershell의 동작이 변경됩니까? 어쩌면 새로운 wirte-host 또는 다른 것.

powershell.exe 
PS C:>_ 
PS C:>fuu 
fuu: this is not a cmdlet so CommandNotFoundException and now i behave diffrent my lord 
PS C:>_ 

그래서 네, 등등 캐치를 시도 알 -> 스크립트하지만 난 기본 동작으로 interactivly 의미!

감사

물건을 지우려면

[UPDATE]. 진짜 사건은 codesigning입니다.

+ ~~~~~~~~~~~~~~ 
    + CategoryInfo   : Sicherheitsfehler: (:) [], PSSecurityException 
    + FullyQualifiedErrorId : UnauthorizedAccess 

만에

정확한 내가 그나마이 경우이 오류가 원하는, 내가 질문을 원하는 당신이 서명 할 DO : ExecutionPolicy 내가 오류를 가지고 당연히 testcode에 서명하는 것을 잊지 경우 AllSignt 및입니까? 예/아니오

.... 그리고 그렇게하십시오.

답변

0

사용이 구조 :

fooo : The term 'fooo' 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:5 char:1 
+ fooo 
+ ~~~~ 
    + CategoryInfo   : ObjectNotFound: (fooo:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

을하고 문자열이있을 때 당신은 파서를하고

$customerror = $Errormessage.reaplace("fooo : The term 'fooo' 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.","Foo is not functin") 

write-output $customerror 
+0

하지만 어떻게처럼 사용자 지정 오류 처리기를 만들 수 있습니다

$Error.Clear() fooo $Errormessage = $Error | Out-String $Errormessage 

당신은받을 것이다 나는 이것들을 정상적인 PS 행동에 추가합니까? 나는 "fuu"호출에 코드 줄을 추가하고 싶지 않다. 나는 ineracive shell의 오류 처리를 조작하고 싶다. –

+0

@AnUser deflult를 사용하여 편집하는 powershell 오류를 수정 하시겠습니까? . 나는 그것이 가능하다는 것을 모른다. 미안, 내 친구. 나는 당신의 질문에 대해 최고의 질문을하기 위해 투표합니다. 그리고 내가 원한다면 나는 내 대답을 제거 할 수 있습니다. – saftargholi

+0

고마워요, 그걸 없애지 마세요. 어쩌면 그걸 좀 지워 버릴 수도 있습니다. –