Skip to content

Support sudo <PowerShell cmdlet> #3232

Closed

Description

Steps to reproduce

sudo Remove-Item foo.txt where foo.txt is owned by root

Expected behavior

foo.txt is deleted

Actual behavior

sudo: Remove-Item: command not found

Activity

  1. added this to the milestone on Feb 28, 2017
  2. MaximoTrinidad commented on Feb 28, 2017

    @MaximoTrinidad

    Hum! Very interesting. But, I think the actual behavior is as expected. As in Windows we don't have a command like sudo.
    But, you could use 'sudo powershell' and then do the remove foo.txt (which was created using 'sudo powershell') then it works when using Remove-Item. Of course, it won't work in a non-elevated permission.

    I would only use 'sudo' on Linux commands ("sudo nautilus") from within PowerShell.

    :)

  3. SteveL-MSFT commented on Mar 1, 2017

    @SteveL-MSFT
    Member

    Even on Windows, it would be good to have similar capability to run a cmdlet as another user or elevated and something that could relied on in portable scripts. May need an RFC for this.

  4. modified the milestones: 6.0.0-beta1, on Mar 16, 2017
  5. pcgeek86 commented on Apr 7, 2017

    @pcgeek86

    This functionality would be useful to work around #3506.

  6. 123 remaining items

  7. bergmeister commented on Feb 9, 2024

    @bergmeister
    Contributor

    With Windows supporting sudo now (in Insiders) as first class citizen, this will allow at least wrap-around functionality: https://devblogs.microsoft.com/commandline/introducing-sudo-for-windows/

    Windows Command Line
    Introducing Sudo for Windows We’re excited to announce the release of Sudo for Windows in Windows 11 Insider Preview Build 26052! Sudo for Windows is a new way for users to run elevated commands directly from an unelevated console session. It is an ergonomic and familiar solution for users who want to elevate a command without having to first open a new elevated console.
  8. agowa commented on Feb 9, 2024

    @agowa

    Only client versions of windows. What is with servers?

  9. charltonstanley commented on Mar 27, 2024

    @charltonstanley
    Contributor

    This issue goes back 7 years, so I may have missed somebody sharing this already, but in case it hasn't, here it is.

    It seems that sudo -s will read the $SHELL environment variable to determine what shell to use to execute the command. I changed it to point to pwsh and that seems to work for my current need of moving a file.

    #!/usr/bin/env pwsh
    
    $Env:SHELL = '/opt/microsoft/powershell/7/pwsh'
    $source = /tmp/file.csv
    $dst = /home/user/tmp/file.csv
    sudo -s Move-Item -Path $source -Destination $dst -Force

    However, if I append -Confirm:$false to the Move-Item cmdlet, I get the following error:

    Move-Item: A parameter cannot be found that matches parameter name 'Confirm\'.
    

    So this kinda works for using sudo against some simple cmdlets on Linux, but for more complex commands you will definitely get unexpected results. YMMW. Use with caution.

  10. GlacierFox commented on Jul 17, 2024

    @GlacierFox

    Just ran into this while creating a script to transfer my published project data over to my home server. I'm using a bash command to achieve it now but would be great to have some sort of sudo mechanism built into to Powershell so I don't have to change style depending on the privileges I hold.

  11. SeeminglyScience commented on Mar 24, 2025

    @SeeminglyScience
    Contributor

    The Engine WG discussed this. We do not feel that this is a problem PowerShell should solve directly. We will monitor the new built-in Windows sudo and see if there are better opportunities to integrate, but if those come up we will open a new issue.

  12. added
    WG-ReviewedA Working Group has reviewed this and made a recommendation
    and removed
    WG-NeedsReviewNeeds a review by the labeled Working Group
    KeepOpenThe bot will ignore these and not auto-close
    on Mar 24, 2025
  13. microsoft-github-policy-service commented on Mar 26, 2025

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as declined and has not had any activity for 1 day. It has been closed for housekeeping purposes.

  14. microsoft-github-policy-service commented on Mar 26, 2025

    @microsoft-github-policy-service
    Contributor

    📣 Hey Joey Aiello (@joeyaiello), how did we do? We would love to hear your feedback with the link below! 🗣️

    🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Enhancementthe issue is more of a feature request than a bugResolution-DeclinedThe proposed feature is declined.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions