Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9155997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:41:37+00:00 2026-06-17T12:41:37+00:00

Scripts (with CmdletBinding) and cmdlets all have a standard -ErrorAction parameter available when being

  • 0

Scripts (with CmdletBinding) and cmdlets all have a standard -ErrorAction parameter available when being invoked. Is there a way then, within your script, if indeed you script was invoked with -ErrorAction?

Reason I ask is because I want to know if the automatic variable value for $ErrorActionPreference, as far as your script is concerned, was set by -ErrorAction or if it is coming from your session level.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:41:37+00:00Added an answer on June 17, 2026 at 12:41 pm

    $ErrorActionPreference is a variable in the global(session) scope. If you run a script and don’t specify the -ErrorAction parameter, it inherits the value from the global scope ($global:ErrorActionPreference).

    If you specify -ErrorAction parameter, the $ErrorActionPreference is changed for your private scope, meaning it’s stays the same through the script except while running code where you specified something else(ex. you call another script with another -ErrorAction value). Example to test:

    Test.ps1

    [CmdletBinding()]
    param()
    
    Write-Host "Session: $($global:ErrorActionPreference)"
    Write-Host "Script: $($ErrorActionPreference)"
    

    Output:

    PS-ADMIN > $ErrorActionPreference
    Continue
    
    PS-ADMIN > .\Test.ps1
    Session: Continue
    Script: Continue
    
    PS-ADMIN > .\Test.ps1 -ErrorAction Ignore
    Session: Continue
    Script: Ignore
    
    PS-ADMIN > $ErrorActionPreference
    Continue
    

    If you wanna test if the script was called with the -ErrorAction paramter, you could use ex.

    if ($global:ErrorActionPreference -ne $ErrorActionPreference) { Write-Host "changed" }
    

    If you don’t know what scopes is, type this in a powershell console: Get-Help about_scopes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cmdlet with the following defintion: [CmdletBinding(DefaultParameterSetName=Path, SupportsShouldProcess=$TRUE)] param( [parameter(Mandatory=$TRUE,Position=0)] [String] $Pattern,
Say I have MyScript.ps1 : [cmdletbinding()] param ( [Parameter(Mandatory=$true)] [string] $MyInput ) function Show-Input
I have a function defined as follows: function Get-LatestProjects { [CmdletBinding()] Param ( [Parameter(ValueFromPipeline
I have two scripts that often need to be run with the same parameter:
CGI scripts should have access to a list of environment variables set by the
Say I have 2 scripts test1.sh #!/bin/sh . ./test2.sh foo test2.sh #!/bin/sh foo(){ echo
I have come across scripts that use: isset($_POST['submit']) as well as code that uses:
I have two scripts that are called in one program, the first script creates
When developing Pig scripts that use the STORE command I have to delete the
Now a lot of scripts to facebook-style fetching data from url, but all of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.