PowerShell / PowerShell/PowerShell

PowerShell class methods may duplicate output from sudo commands

Open
#26,067 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs-Triage
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

Description

Prerequisites
Steps to reproduce
  1. Make sure to have a WSL named "NewDistro" with a user "nico" that can run sudo without password or adjust the distro/user in the code below.
  2. Run the sample program: powershell.exe -ExecutionPolicy Bypass -File ".\Powershell-class-bug.ps1"
  3. Observe that sudo prompts appear twice for class methods, once for functions
  4. This affects any external process execution, not just WSL/sudo
  5. Commands that modify state will execute their changes twice

Impact: This duplicate execution causes multiple serious issues:

  • Interactive commands prompt for input twice (passwords, confirmations)
  • Commands with side effects execute twice (file creation, database operations)
  • Performance degradation due to unnecessary duplicate operations
  • Inconsistent behavior between class methods and regular functions
  • Makes class-based architectures unreliable for external process automation
Expected behavior
Class methods and functions should execute external commands identically
Actual behavior
Class instance methods execute external commands twice
Error details
Run sample program
Environment data
- PowerShell Version:7.5.3
- PowerShell Version: 5.1.26100.6584
- OS: Microsoft Windows NT 10.0.26100.0
- WSL Version:
  - WSL-versie: 2.4.13.0
  - Kernelversie: 5.15.167.4-1
  - WSLg-versie: 1.0.65
  - MSRDC-versie: 1.2.5716
  - Direct3D-versie: 1.611.1-81528511
  - DXCore-versie: 10.0.26100.1-240331-1435.ge-release
  - Windows-versie: 10.0.26100.6584
Visuals

powershell5-class-bug.txt
powershell7-class-bug.txt

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the attached powershell5-class-bug.txt and powershell7-class-bug.txt samples with the reported PowerShell and WSL setup, comparing class methods with regular functions. Trace the external-process behavior shown by the reproducer; done means class methods execute each external command once, matching functions, without duplicate prompts or side effects.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.