際際滷

際際滷Share a Scribd company logo
Error Handling
IN
Powershell
 Speaker : Nitesh Bhat
 Twitter : @bhat_nitesh
 Facebook:bhat420
 Blog :http://yourscriptsolution.blogspot.in/
Introduction of Topic
Talk on .
1. Errors = Exceptions = ?
2. $ErrorActionPreference and ErrorAction
3. Predefine Variable ($error)
4. -Errorvariable
5. General Tab
6. Non-Powershell Commands
Errors and Exception
$ErrorActionPreference and ErrorAction
1. Inquire
When error occur it ask user for conformation
We cannot use it in script as it required user interaction which change the meaning of
automation is it
We can use it to check command functionally but not prefer
2. Continue
This is a default settings of built-in variable
When error occur it will not ask any thing to user display the error and keep going
3. Silently Continue
Does not display any error and keep going
I wish my girl friend should be like this
4. Stop
 When error occur it terminate the script
 Also terminate non-terminating script too
 Using try and catch is good option
Predefine Variable ($error)
1. Predefined variable
2. Data type : Array
3.Default Array Size is 256
Note: To know how many Predefine Variable (Get-Variable)
-Errorvariable (-EV)
1. One of the Common Parameters
2. parameter accepts the name of variable
3. If command generate an error its place into that variable
4. Best way to use with silentlycontinue option of Error
Action
Common parameters
Get-help about_commonparameters |more
General Trap /Trap Constructs
1. Introduced in Powershell v1
2. When ever trappable exception occurs Powershell jump back
in your script and execute TRAP CONSTRUCTS
3. It always placed starting of script
Non-Powershell Commands
 $? -> just returns True or False depending on
whether the last command (cmdlet or native)
exited without error or not
 $LastExitCode
Thanks you
Any Questions ????

More Related Content

Error handling

  • 1. Error Handling IN Powershell Speaker : Nitesh Bhat Twitter : @bhat_nitesh Facebook:bhat420 Blog :http://yourscriptsolution.blogspot.in/
  • 3. Talk on . 1. Errors = Exceptions = ? 2. $ErrorActionPreference and ErrorAction 3. Predefine Variable ($error) 4. -Errorvariable 5. General Tab 6. Non-Powershell Commands
  • 5. $ErrorActionPreference and ErrorAction 1. Inquire When error occur it ask user for conformation We cannot use it in script as it required user interaction which change the meaning of automation is it We can use it to check command functionally but not prefer 2. Continue This is a default settings of built-in variable When error occur it will not ask any thing to user display the error and keep going 3. Silently Continue Does not display any error and keep going I wish my girl friend should be like this 4. Stop When error occur it terminate the script Also terminate non-terminating script too Using try and catch is good option
  • 6. Predefine Variable ($error) 1. Predefined variable 2. Data type : Array 3.Default Array Size is 256 Note: To know how many Predefine Variable (Get-Variable)
  • 7. -Errorvariable (-EV) 1. One of the Common Parameters 2. parameter accepts the name of variable 3. If command generate an error its place into that variable 4. Best way to use with silentlycontinue option of Error Action Common parameters Get-help about_commonparameters |more
  • 8. General Trap /Trap Constructs 1. Introduced in Powershell v1 2. When ever trappable exception occurs Powershell jump back in your script and execute TRAP CONSTRUCTS 3. It always placed starting of script
  • 9. Non-Powershell Commands $? -> just returns True or False depending on whether the last command (cmdlet or native) exited without error or not $LastExitCode

Editor's Notes

  1. Note: Terminating and non Terminating
  2. Note: $maximumerrorcount