none
Powershell: help command reference for CommonParameter -Errorvariable not working RRS feed

  • Question

  • Dear Readers:

    Is this a user error or a description error by Microsoft: I found this example on the help menu in powershell by typing help about_commonParameter and see the pages where it talks about -Errorvariable:

     For example, the following command creates the $a variable and then
     stores any errors in it:

         Get-Process -Id 6 -ErrorVariable a

    Issue: When I type the above command it does not create a variable with $a with any errors.

    Thank-you

    SQL 75

    


    • Edited by SQL75 Friday, April 17, 2015 1:43 PM
    Friday, April 17, 2015 1:38 PM

Answers

  • Hi,

    I'm not clear on what you're asking.

    PS C:\Scripts\PowerShell Scripts> Get-Process -Id 5 -ErrorVariable a
    Get-Process : Cannot find a process with the process identifier 5.
    At line:1 char:1
    + Get-Process -Id 5 -ErrorVariable a
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (5:Int32) [Get-Process], ProcessCommandException
        + FullyQualifiedErrorId : NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand
     
    
    PS C:\Scripts\PowerShell Scripts> $a
    Get-Process : Cannot find a process with the process identifier 5.
    At line:1 char:1
    + Get-Process -Id 5 -ErrorVariable a
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (5:Int32) [Get-Process], ProcessCommandException
        + FullyQualifiedErrorId : NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand


    Don't retire TechNet! - (Don't give up yet - 13,225+ strong and growing)

    • Edited by Mike Laughlin Friday, April 17, 2015 1:44 PM
    • Marked as answer by SQL75 Friday, April 17, 2015 1:55 PM
    Friday, April 17, 2015 1:44 PM

All replies

  • Hi,

    I'm not clear on what you're asking.

    PS C:\Scripts\PowerShell Scripts> Get-Process -Id 5 -ErrorVariable a
    Get-Process : Cannot find a process with the process identifier 5.
    At line:1 char:1
    + Get-Process -Id 5 -ErrorVariable a
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (5:Int32) [Get-Process], ProcessCommandException
        + FullyQualifiedErrorId : NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand
     
    
    PS C:\Scripts\PowerShell Scripts> $a
    Get-Process : Cannot find a process with the process identifier 5.
    At line:1 char:1
    + Get-Process -Id 5 -ErrorVariable a
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (5:Int32) [Get-Process], ProcessCommandException
        + FullyQualifiedErrorId : NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand


    Don't retire TechNet! - (Don't give up yet - 13,225+ strong and growing)

    • Edited by Mike Laughlin Friday, April 17, 2015 1:44 PM
    • Marked as answer by SQL75 Friday, April 17, 2015 1:55 PM
    Friday, April 17, 2015 1:44 PM
  • Thanks Mike i think it was a local error. For some reason it was not working on my screen. But its fine now.

    Thank-you

    SQL 75

    Friday, April 17, 2015 1:55 PM