PowerShell error code “1”

Configurare noua (How To)

Situatie

PowerShell exited with code ‘1’ is a generic error meaning the script or command failed / encountered an error.

Solutie

Run the script manually in PowerShell and check the error:

powershell
powershell.exe -File "C:\path\to\script.ps1"

Check the last exit code:

powershell
echo $LASTEXITCODE
$?

Enable verbose/error output:

powershell
powershell.exe -File "script.ps1" -Verbose 2>&1

Redirect all output to a log:

powershell
powershell.exe -File "script.ps1" *> C:\logs\output.log

Common Fixes

1. Execution Policy blocking the script:

powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# or run with bypass:
powershell.exe -ExecutionPolicy Bypass -File "script.ps1"

2. Run as Administrator Right-click PowerShell → Run as Administrator, then re-run the script.

3. Check for $ErrorActionPreference If set to Stop, any error will terminate the script:

powershell
$ErrorActionPreference = "Continue"  # or "SilentlyContinue" to suppress

4. Wrap in try/catch to see the real error:

powershell
try {
    # your code here
} catch {
    Write-Host "Error: $_"
    exit 1
}

5. Missing module:

powershell
Install-Module -Name ModuleName -Force
Import-Module ModuleName

If Running from a Pipeline / Task Scheduler / CI-CD

The exit code 1 is passed back from PowerShell to the calling process. To see what caused it:

  • Task Scheduler: Check the task history and Last Run Result
  • Azure DevOps / GitHub Actions: Look at the full job log above the exit code message
  • Jenkins / other CI: Scroll up in the console output for the actual error message.

Tip solutie

Permanent

Voteaza

(9 din 13 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?