How to do it...

  1. Let's run a command that will result in an error. For now, let us not focus on the syntax of the command; our only goal for now is to generate an error. At the first line of the script window, type in the following:
PS> Get-ChildItem /home/ram/random-directoryPS> Write-Host "Hello world!"
  1. Run the two-liner script using the F5 key:

PowerShell is prompt to show an error. It also displays the Hello world! string.

  1. Let's set the error action preference, using the variable, ErrorActionPreference. We know there's such a variable ...

Get PowerShell Core for Linux Administrators Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.