$error[0] output question

Welcome Forums General PowerShell Q&A $error[0] output question

This topic contains 4 replies, has 4 voices, and was last updated by

 
Participant
3 years, 2 months ago.

  • Author
    Posts
  • #30860

    Participant
    Points: 0
    Rank: Member
    PS C:\> $error[0]
    
    Set-Acl : Attempted to perform an unauthorized operation.
    At line:1 char:8
    + set-acl < <<<  c:\test -AclObject $acl
        + CategoryInfo          : PermissionDenied: (C:\test:String) [Set-Acl], UnauthorizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetAclCommand
    

    Is there a way to have $errror[0] just show 'Attempted to perform an unauthorized operation.' in this example?

  • #30861

    Participant
    Points: 0
    Rank: Member

    Try

    $error[0].Exception 
  • #30862

    Participant
    Points: 324
    Helping Hand
    Rank: Contributor

    I typically use:

    $error[0].Exception.Message
    
  • #30863

    Member
    Points: 0
    Rank: Member

    Well, you could do $error[0].Exception.Message . If you just want to change the formatting of the ErrorRecord objects, that's a bit more involved. However, there is one easy solution that you might like: $ErrorView = 'CategoryView'

  • #30864

    Participant
    Points: 0
    Rank: Member

    Damn you guys rock, thats perfect! Thanks all!

The topic ‘$error[0] output question’ is closed to new replies.