Implementation:20000419 Fauxnix resolvePowerShell
| Knowledge Sources | |
|---|---|
| Domains | Host_Selection, Security, PowerShell |
| Last Updated | 2026-10-26 00:00 GMT |
Overview
Concrete host selector that resolves the process-wide PowerShell executable from a trusted SystemRoot path (Desktop/5.1 default) or from an opt-in FAUXNIX_PS=pwsh PATH search, never trusting the current directory or an unvalidated PATH entry.
Description
The resolvePowerShell function (src/powershell.ts) selects the PowerShell host fauxnix will spawn. By default (no FAUXNIX_PS) it returns Windows PowerShell 5.1 at %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe — a trusted, drive-absolute system path that resists PATH tampering. When FAUXNIX_PS=pwsh (or pwsh.exe) it searches PATH entries for pwsh.exe, excluding the current working directory and non-absolute entries. FAUXNIX_PS=powershell explicitly selects the Desktop host. The result is a PowerShellSelection with the absolute executable, expectedEdition (Desktop or Core), configured flag, and an optional error when the host cannot be found or the env value is invalid. powerShellDisplay and powerShellMissingMessage format human-readable diagnostics for fauxnix check and doctor.
Usage
Called by FauxnixSession constructor (process-wide selection), runCheck (CLI check verb), and hasPowerShell (differential oracle gate). The selection is resolved once per session and reused for all invocations.
Code Reference
Source Location
- Repository: fauxnix
- File: src/powershell.ts
- Lines: resolvePowerShell L125-154; powerShellDisplay L156-163; powerShellMissingMessage L165-178; POWERSHELL_ARGS L4-9
Signature
export const POWERSHELL_ARGS = ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass'] as const;
export type PowerShellEdition = 'Desktop' | 'Core';
export interface PowerShellSelection {
readonly executable: string;
readonly expectedEdition: PowerShellEdition;
readonly configured: boolean;
readonly requested?: string;
readonly error?: string;
}
export function resolvePowerShell(
env?: NodeJS.ProcessEnv,
options?: { cwd?: string; exists?: (candidate: string) => boolean },
): PowerShellSelection;
export function powerShellDisplay(selection: PowerShellSelection): string;
export function powerShellMissingMessage(selection: PowerShellSelection): string;
Import
import { resolvePowerShell, POWERSHELL_ARGS, powerShellDisplay } from './powershell.js';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| env | NodeJS.ProcessEnv | No | Reads FAUXNIX_PS, SystemRoot, PATH (defaults to process.env) |
| options.cwd | string | No | Working directory to exclude from PATH search (default process.cwd()) |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | PowerShellSelection | Absolute executable, expectedEdition, configured, optional error |
Usage Examples
Default: Trusted Desktop Path
const sel = resolvePowerShell();
// sel.executable → "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
// sel.expectedEdition → "Desktop"
Opt-in PowerShell 7
const sel = resolvePowerShell({ ...process.env, FAUXNIX_PS: 'pwsh' });
// sel.executable → first pwsh.exe in an eligible absolute PATH entry
// sel.expectedEdition → "Core"
Check Verb Probe
const sel = resolvePowerShell();
console.log('powershell : ' + powerShellDisplay(sel));
if (sel.error) { console.error(sel.error); }