How to do it...

You should have the profile open now. It would currently be empty. Let us now customise PowerShell's error action behaviour. Remember that we said that setting ErrorActionPreference to SilentlyContinue at the terminal was temporary. Let us now ensure that ErrorActionPreference is permanently set to SilentlyContinue every time we launch PowerShell.

  1. Switch to the terminal window. If you have the window open since the last recipe, restart PowerShell.
  2. Let us see what the error action preference is at the moment.
PS> Get-Variable ErrorActionPreference
Continue
  1. Switch to VS Code. The profile should already be open for edits.
  2. At the very first line, type in:
PS> Set-Variable ErrorAction SilentlyContinue
  1. Save the profile and close the file.
  2. At the terminal, type exit to exit from PowerShell. Start PowerShell again.
  3. Let us now check what the value is for ErrorActionPreference. At the prompt, type:
PS> $ErrorActionPreference
SilentlyContinue
  1. To ensure the preference is indeed in place, type:
PS> Get-ChildItem /home/ram/random-directory

The cursor simply returned to the prompt at the next line without throwing an error.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.45.162