PowerShell Errors and Exceptions Handling

Ғылым және технология

Learn how to handle PowerShell Errors and Exceptions. See how to recognize and deal with non-terminating and terminating PowerShell errors. Take control and handle various errors with try catch. Explore rich PowerShell error objects and see how to drill down into error properties. Wrap up with a practical example where you can provide better feedback to your users when your PowerShell code encounters the unexpected.
Corresponding TechThoughts write-up:
www.techthoughts.info/powersh...
▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬
00:00 - Intro
00:27 - PowerShell has two pipelines
01:18 - Understanding PowerShell's non-terminating behavior
04:31 - Forcing errors to terminate in PowerShell
06:21 - Try / Catch intro
09:13 - Try / Catch with ErrorAction
14:26 - Try / Catch / Finally
15:23 - PowerShell rich error object
20:48 - Example 2 rich error object
21:57 - PowerShell error variable
23:21 - Final Example
27:22 - Outro
Learn PowerShell - Episode 8 - PowerShell Errors and Exceptions Handling
Reference PowerShell code examples from this episode:
github.com/techthoughts2/Lear...
Check out the complete Learn PowerShell KZread Playlist:
• Learn PowerShell
~
/ jakemorrison
My recommended books for learning PowerShell:
(these affiliate links cost you nothing extra and help support this channel)
- Learn PowerShell in a Month of Lunches: amzn.to/3mlbizz
- Learn PowerShell Scripting in a Month of Lunches: amzn.to/3MtxJxe
- Windows PowerShell in Action: amzn.to/3xkjGp4
- PowerShell Cookbook: amzn.to/3tgCq6F
If you are able, and found this content valuable, please consider a secure donation in the link below. Your contribution helps offset the costs of producing this PowerShell series. Much appreciated!
www.paypal.com/cgi-bin/webscr...
Learn PowerShell online free in this operationally focused PowerShell series. These PowerShell tutorials are designed to get you ramped up and using PowerShell quickly. Each episode provides practical PowerShell examples for using PowerShell in the real world. Whether you are a PowerShell beginner or seeking advance PowerShell training, this Learn PowerShell series covers the topics you'll need to be effective with PowerShell!
These videos were recorded on a lot of my older equipment.
My newer videos use the following equipment:
- Camera: amzn.to/3MsjQPu
- Lens: amzn.to/3NrsKhJ
- Teleprompter: amzn.to/3monqQc
- Mic: Audio-Technica AT2035
- Mic Preamp: amzn.to/3tlOvY6
- Mic Arm: amzn.to/3NXJTiP
- Audio Interface: amzn.to/3xqPqJu
- Lighting: amzn.to/3O1Z2zR
- Rear color lighting: amzn.to/3H5MIMI
#learnPowerShell #PowerShell #PowerShelltraining #PowerShellTutorial

Пікірлер: 39

  • @thecrazzxz3383
    @thecrazzxz33833 жыл бұрын

    We can say that it was an exceptional tutorial

  • @5n4keyes
    @5n4keyes Жыл бұрын

    2 Years later and this was still perfect! made it simple to understand, and exactly what i needed. Thank you.

  • @alphabeta4149
    @alphabeta41494 жыл бұрын

    Probably the clearest and most concise tutorial I've seen on Powershell. Who is this guy?

  • @NancyRileyNuniverse

    @NancyRileyNuniverse

    3 жыл бұрын

    Agreed. There are some more well known folks that make these videos and I feel like they just joke and never get to the meat of what we need, immediately. This gentleman rocks at training!!!

  • @Cullinan000
    @Cullinan0004 жыл бұрын

    These videos are pure gold. Thank you!

  • @Tegle9
    @Tegle92 жыл бұрын

    This is tremendously helpful. As a student who is used to buying Udemy courses this free course it's the rough equivalent of finding a wallet full of cash on the middle of the road. Great job :)

  • @piggiesgosqueal8066

    @piggiesgosqueal8066

    2 жыл бұрын

    "It's a steal"

  • @prasadsardeshmukh3898
    @prasadsardeshmukh38984 жыл бұрын

    One of the best resources for 'Exception Handling in PowerShell'. Thanks a lot!

  • @NancyRileyNuniverse
    @NancyRileyNuniverse3 жыл бұрын

    This really is an exceptional video. I have been trying to catch on to how to work with errors and I believe I finally have it!!! Thanks so much - seriously, keep making videos!!!!

  • @beku2283
    @beku22834 жыл бұрын

    Very good flow and clear explanations! Excellent!

  • @jordanyefet2679
    @jordanyefet26794 жыл бұрын

    Very helpful, thank you for your deep and knowledgeable explanations.

  • @vorkpalur
    @vorkpalur4 жыл бұрын

    Thanks a lot for your effort and sharing the knowledge for free!

  • @BenyBenator
    @BenyBenator3 жыл бұрын

    This is exactly what I needed answers for, and more. You are awesome! Thank you.

  • @piggiesgosqueal8066
    @piggiesgosqueal80662 жыл бұрын

    Thanks! Very useful.

  • @juansanchez6685
    @juansanchez6685 Жыл бұрын

    Great Video!

  • @limacal
    @limacal4 жыл бұрын

    Great Explanation! Thank you for the excellent class

  • @Techthoughts2

    @Techthoughts2

    4 жыл бұрын

    Glad it was helpful!

  • @amarchougale9471
    @amarchougale947110 ай бұрын

    Really well explained

  • @bilashshahi
    @bilashshahi3 жыл бұрын

    Thank you so much for this wonderful tutorial :) I subscribed

  • @pallabba
    @pallabba3 жыл бұрын

    excellent..clearly explained...

  • @kishorshevate374
    @kishorshevate3744 жыл бұрын

    Amazing Amazing Amazing... Excellent

  • @Techthoughts2

    @Techthoughts2

    4 жыл бұрын

    Thank you so much 😀

  • @robofski
    @robofski4 жыл бұрын

    Excellent series, will you be doing more?

  • @Techthoughts2

    @Techthoughts2

    4 жыл бұрын

    Absolutely! Stay tuned!

  • @dilatedconciousness
    @dilatedconciousness2 ай бұрын

    Very good

  • @FapilsonAndrade-rz3wv
    @FapilsonAndrade-rz3wv3 жыл бұрын

    buen tutorial de power shell

  • @AmrXcellent
    @AmrXcellent Жыл бұрын

    So good knowledge in general, however I do not recommend changing the -erroraction to stop because as you said, that defeats the entire purpose of Powershell, you don't want your program to stop because of one thing it didnt find. Your are better off -ErrorAction SilentlyContinue and then capture that if statement on the object and handle the output based if the object actually returned or not. # PowerShell -ErrorAction SilentlyContinue example Clear-Host $SrvName = "Printer Spooler" $Service = Get-Service -display $SrvName -ErrorAction SilentlyContinue if (-Not $Service) {$SrvName + " is NOT installed check the name."} else {$SrvName + " is installed." $SrvName + "'s status is: " + $service.Status } which is better because it lets you actually handle the error as you want, if it is a foreach loop, you can do a continue and it will skip the object and go to the next one in the loop. Finally, you can set your preference for -ErrorAction by setting this variable in your script (the default is continue - which will give an error on the screen but will continue the script). You can change that to stop or SilentlyContinue. $ErrorActionPreference = "SilentlyContinue"

  • @ddw1518
    @ddw1518 Жыл бұрын

    Hello, techThoughts Thank you for your tutorial first. I have a question that can we use the powershell to maniplate the website for automatic purpose (like login an user account, and then download something in a webpage).

  • @Techthoughts2

    @Techthoughts2

    Жыл бұрын

    Yes, check out Selenium: github.com/adamdriscoll/selenium-powershell

  • @ankitsoni9664
    @ankitsoni96644 жыл бұрын

    hey, thanks for creating great videos, they are very easy to understand. as far as I have understood the default -erroraction in Continue, but for below code its sop, could you please have a look. try{ $a = 1/0 $a Get-Process } catch{ Write-Warning "This is a warning " }

  • @Techthoughts2

    @Techthoughts2

    4 жыл бұрын

    When more basic errors (non-cmdlet) like math operations, syntax, and others are wrapped in a try/catch this tells PowerShell to switch the behavior of those errors to stop. It will then go to the catch. Your $a = 1/0 is a math operation error in a try/catch, so the behavior will be stop. If that same operation were outside of the try/catch it would be continue.

  • @vb9950
    @vb9950 Жыл бұрын

    6:44 Line number 20. What is the use of semicolon there? is it kind of terminating character for an expression like in c/c++?

  • @kombatformortals
    @kombatformortals2 жыл бұрын

    Could some elaborate a bit on why inputting '1/0' changed the array stored as 0?

  • @ejhaboc6862
    @ejhaboc68622 жыл бұрын

    Hello, I just transferred my script to Powershell version 2 on a windows server, however it is somehow not recognizing the objects Exception.Message from variable $Error, would you be able to advice? Checking on format-list and Get-Member though, it should be listed

  • @durgapavani3805
    @durgapavani38054 жыл бұрын

    Hi, could you tell me how to written error codes

  • @Diabloisbackk
    @Diabloisbackk2 ай бұрын

    HOW CAN I FIX THIS ERROR ??? Windows PowerShell is not properly responding. check if it is working, and not locked in Constrained Language Mode.

  • @ridewithnarenchand2579
    @ridewithnarenchand25793 жыл бұрын

    how to catch errors in CSV if we are checking lst reboot time of remote servers by using: Get-CimInstance -classname win32_operatingsystem -property * -computername $servers -ErrorAction Stop | select csname,lastBootupTime,Caption | Out-File $log

  • @anontough6907
    @anontough6907 Жыл бұрын

    Insane, it was easier to found how to catch and output error on terminal than actually printing the process in the terminal. I hate powershell, the docs are garbage.

  • @saeedredrose
    @saeedredrose3 жыл бұрын

    These videos are pure gold. Thank you!

Келесі