Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. function Foobar {
  2. throw "Error in FooBar"
  3. }
  4.  
  5. function Bar {
  6. FooBar
  7. }
  8.  
  9. function Foo {
  10. Bar
  11. }
  12.  
  13. try {
  14. $sb = ${function:Foo}
  15. $sb.Invoke()
  16. }
  17. catch {
  18. $ErrorMessage = $_.Exception.Message
  19. $line = $_.InvocationInfo.ScriptLineNumber
  20. $script_name = $_.InvocationInfo.ScriptName
  21. write-host "<--Error: Occurred on line $line in script $script_name."
  22. Write-host "<--Error: $ErrorMessage"
  23. }
  24.  
  25. $sb = ${function:Foo}
  26. $sb.Invoke()
  27.  
  28. $func_info = get-command Foo
  29. Invoke-Command $func_info.ScriptBlock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement