- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of $ErrorView in PowerShell?
$Errorview variable determines the display format of the error message in PowerShell. Before PowerShell 7 there were mainly two views,
Normal View (Default view)
Category View
With PowerShell version 7, one new additional error view category is included and now there are 3 $ErrorView categories for version 7.
Concise View (Default)
Normal View
Category View
We will understand each view one by one.
A ) Normal View
It is the default view before PowerShell version 7 and it produces the detailed multiline errors and bit noisy. It includes the exception name, category, line number of the error, etc.
$ErrorView = 'NormalView' Get-ChildItem C:\NoDirectory
Output
Get-ChildItem : Cannot find path 'C:\NoDirectory' because it does not exist. At line:1 char:1 + Get-ChildItem C:\NoDirectory + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\NoDirectory:String) [Get-ChildItem], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
B) Category View
Single liner and structured view, designed for the production environment. Its format is as below.
{Category}: ({TargetName}:{TargetType}):[{Activity}], {Reason}
For example
$ErrorView = 'CategoryView' Get-ChildItem C:\NoDirectory
Output
ObjectNotFound: (C:\NoDirectory:String) [Get-ChildItem], ItemNotFoundException
C) Concise View
The default view in PowerShell version 7. It provides a concise error message. If the error is from thecommand line it’s a single line error message.
For example
$ErrorView = 'ConciseView' Get-ChildItem C:\NoDirectory
Output
Get-ChildItem: Cannot find path 'C:\NoDirectory' because it does not exist.
If the error is from the script then it is a multiline error message that contains the error message and the line number for the error.
$ErrorView = 'ConciseView' PS C:\> C:\Temp\TestPS1.ps1
Output
Error message in Concise view Get-ChildItem: C:\Temp\TestPS1.ps1:2 Line | 2 | Get-ChildItem c:
onDirectory | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Cannot find path 'C:
onDirectory' because it does not exist.
- Related Articles
- What is use of $error variable in PowerShell?
- What is the use of Get-Process command in PowerShell?
- What is the use of $Lastexitcode and $? Variable in PowerShell?
- What is the use of the Get-Error cmdlet in PowerShell?
- What is the use of Passthru parameter in Stop-Process in PowerShell?
- What is the use of -Force parameter in Get-ChildItem in PowerShell?
- What is the breakpoint in PowerShell?
- What is the PowerShell Workflow?
- What is Array in PowerShell?
- What is splatting in PowerShell?
- How to use the ValidateLength attribute in PowerShell?
- How to use the ErrorActionPreference variable in PowerShell?
- How to use the ErrorAction parameter in PowerShell?
- How to use the tree command in PowerShell?
- How to use the Timeout command in PowerShell?
