-ErrorAction SilentlyContinue location

Welcome Forums General PowerShell Q&A -ErrorAction SilentlyContinue location

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

1 year, 12 months ago.

  • Author
  • #67104

    Points: 3
    Rank: Member


    I'm trying to run this

    $servers | foreach { (Get-Service -Name gservice* -ErrorAction SilentlyContinue -computername $_ ) | Select-Object machinename,Name,Status} |FT -autosize

    and I see errors although I added the "-ErrorAction SilentlyContinue" . I tried to move it to different locations but still , I see errors .

    I also tried "just" Get-Service -Name gservice -ErrorAction SilentlyContinue -computername abc and still ot errors .

    is there a way to add -ErrorAction SilentlyContinue to get-service or I need to change the script to try&catch or something else ?

  • #67119

    Points: 41
    Rank: Member

    It looks like if you don't have the wildcard then a non-terminating error is thrown, -ErrorAction only applies to non-terminating errors. You don't get nasty red output but you can view the error that's written to the error pipeline.

    If you do use a wildcard a terminating error is thrown which is why -ErrorAction has no effect. It's a terminating error so the cmdlet stops running.

    Get-Service -ComputerName NonExistant -Name W -ErrorAction SilentlyContinue
    Write-Output $error[0]
    Get-Service -ComputerName NonExistant -Name W* -ErrorAction SilentlyContinue

    You will need to use a try/catch block for error handling.

    • #67401

      Points: 3
      Rank: Member

      It did the job

The topic ‘-ErrorAction SilentlyContinue location’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort