Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

PowerShell Troubleshooting

Direct answer

Troubleshoot PowerShell scripts with Set-PSDebug, Write-Verbose and -Verbose, inspecting [$Error[0] | Format-List * -Force](/topic.php?command=-windows-16f722c47d271d0223a4ee768680), the execution policy, module versions and the PowerShell edition in use.

When to use this

Use this when a PowerShell script fails and you need the full error record, versions and policy.

First 30 seconds

1. Read full error records (exception, category, invocation).

2. Check module versions and edition (5.1 vs 7).

3. Remoting issues: WinRM, auth, double hop.

4. Execution policy/signing.

5. Reproduce and add a Pester test.

Operational verification

error → details → environment → fix → test

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
PowerShell 7.6/current
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformPowerShell 7.6/current · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior. · Windows PowerShell / PowerShell
Key command$Error[0] | Format-List * -Force
Scope / prerequisiteUse this when a PowerShell script fails and you need the full error record, versions and policy.
Reference · 1
What next?3 suggested next steps
Catalog command links1
Evidence0
On this pageJump to a specific section
Automation command reference

Primary Commands

Configuration and operational commands for this Topic.

Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Command read-back and what it shows Verify boundary

Known-good is the relevant error record disappears for a controlled rerun, the cmdlet returns expected state/result and the original automated task plus independent read-back succeed; broken state is a repeatable exception/category/target object identifies the same failing step or the script completes while postcondition/read-back remains incorrect. $Error[0] shows the most recent error record in that PowerShell session only, but it does not show all non-terminating issues, target state or end-to-end workflow success.

Step 2 Verification path Verify boundary

Start with $PSVersionTable and Get-Command <name> -All, then inspect the exact ErrorRecord and InvocationInfo. If native code is involved capture $LASTEXITCODE; if remoting/API is involved capture transport/status/correlation metadata; if a mutation was intended query the target state independently. Re-run the exact original operation after the smallest correction.

Step 3 Common mistakes Narrow the fault
  • Not reading $Error[0] | Format-List -Force.
Step 4 Observation-driven branch and next-check logic Narrow the fault

If the newest error is parser/command-not-found/binding related, fix script/module context; if the error is transport/auth/provider related, inspect credentials/remoting/API; if the command reports no error but state is wrong, perform explicit read-back and inspect application/provider logs.

Step 5 Where it fails Narrow the fault

Do not infer root cause from the layer that reported the final symptom. Command-not-found, binding, authentication, authorization, transport, target validation and eventual convergence are different boundaries. Pcornel should preserve precise reference/evidence context and hand the actual error/output to ChatGPT for synthesis instead of encoding a large static troubleshooting wizard.

Key points
  • Read full error record.
  • Check edition and modules.
  • Check execution policy.
Key checks
  • $Error[0] | Format-List * -Force — error details
  • Set-PSDebug -Trace 1 — trace
  • Start-Transcript -Path log.txt — capture session
ReferenceHow it works2 sections · depth on demand

Method

PowerShell troubleshooting isolates whether the problem is the command, the input, the environment or the remote target.

1. Check the version and host: $PSVersionTable, Windows PowerShell 5.1 vs PowerShell 7.

2. Read the full error: $Error[0] | Format-List * -Force, including InvocationInfo and Exception.InnerException.

3. Make errors terminating: -ErrorAction Stop with try/catch.

4. Trace: Set-PSDebug -Trace 1, Start-Transcript.

5. Check modules: Get-Module -ListAvailable <name>.

6. For remoting: Test-WSMan srv01, firewall 5985/5986, permissions.

ErrorLikely cause
"running scripts is disabled"Execution policy
"term is not recognized"Module not loaded or wrong version
"Access is denied" (remoting)Not in Remote Management Users/Administrators
Second-hop failuresDelegation not configured

How it works

PowerShell Troubleshooting is governed by PowerShell parser/runtime, command/module binding, remoting/provider execution and the target resource. PowerShell resolves commands and parameters, invokes providers/modules and surfaces terminating or non-terminating errors through error records containing exception, category, target object and invocation context; $Error is session-local history, not a global system log. Module versions, execution context, credentials, remoting transport and target APIs are separate things to check. The important state separation is that a command can emit non-terminating errors yet continue, and an empty $Error in a new session does not show an earlier automation run was successful.

ReferenceImportant terms & boundaries1 section · depth on demand

PowerShell mechanics

PowerShell troubleshooting is fastest when the execution path is decomposed into engine/host identity, command resolution, parsing and parameter binding, module/provider state, transport or external API/native process, target mutation and independent read-back. Error text alone can collapse several of these layers, while ErrorRecord/InvocationInfo and command metadata preserve where the failure actually occurred.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
ReferenceConfiguration & state1 section · depth on demand

Authoring and lifecycle

Capture a minimal reproducible invocation plus PowerShell version/edition, command source/version, relevant parameters with secrets redacted, target identity and timestamp. Prefer read-only inspection before mutation and keep the original failing output intact. Change one boundary at a time and record rollback where the test affects connectivity, permissions or production state.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical examples

Configuration & expected output

Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.

Configuration example

PowerShell 7.6/current 7.6/currentMinimal authored PowerShell pattern for PowerShell Troubleshooting

Assumptions: Review target identity, permissions and environment before mutation.

$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
# Capture exact failure context before remediation.
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docPowerShell 7.6/current 7.6/current

Microsoft Learn documentation reviewed for bounded PowerShell reference claims. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_error_handling?view=powershell-7.6 · confidence 94%
Embedded reference data

Quick lookup tables

PowerShell Troubleshooting · PowerShell operational reference

Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.

BoundaryPowerShell Troubleshooting reference
Runtime identityPowerShell edition/version + command/module source
Persistent intentScript/module/config prerequisites under source control
VerificationRead-only discovery → execution evidence → independent target read-back
Output contractStructured objects/streams before formatting
Failure boundarySeparate engine/binding from transport/API/native and target-state failures
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

Formatted red error text is not the complete diagnostic object. Non-terminating and terminating errors have different control flow, native failures use exit codes, remote errors can be serialized, and API failures may be represented by HTTP/domain responses. Preserve structured fields and avoid reducing evidence to a screenshot or paraphrased message.

Confirmation

Confirm action

Continue?