PowerShell / PowerShell/PowerShell
PowerShell class methods may duplicate output from sudo commands
Open
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
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
- 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.
- Run the sample program:
powershell.exe -ExecutionPolicy Bypass -File ".\Powershell-class-bug.ps1" - Observe that sudo prompts appear twice for class methods, once for functions
- This affects any external process execution, not just WSL/sudo
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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