Use this when a PowerShell script fails and you need the full error record, versions and policy.
PowerShell Troubleshooting
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.
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.
error → details → environment → fix → test
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
$Error[0] | Format-List * -ForcePrimary Commands
Configuration and operational commands for this Topic.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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.
- Read full error record.
- Check edition and modules.
- Check execution policy.
$Error[0] | Format-List * -Force— error detailsSet-PSDebug -Trace 1— traceStart-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.
| Error | Likely 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 failures | Delegation 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.
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
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: Review target identity, permissions and environment before mutation.
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
# Capture exact failure context before remediation.Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%Quick lookup tables
PowerShell Troubleshooting · PowerShell operational reference
Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.
| Boundary | PowerShell Troubleshooting reference |
|---|---|
| Runtime identity | PowerShell edition/version + command/module source |
| Persistent intent | Script/module/config prerequisites under source control |
| Verification | Read-only discovery → execution evidence → independent target read-back |
| Output contract | Structured objects/streams before formatting |
| Failure boundary | Separate engine/binding from transport/API/native and target-state failures |
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.