You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Reacted by Trevor Sullivan, Kelcey Vehanen, Josh Cotton, Michael Klement, Yu Zhang, Rob Reynolds, Miodrag Milić, Manfred Wallner, Vasily Sidorov, Oleg Solomko and 76 more
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.
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.
Reacted by Kitt Holland, Jakub Bereżański, Tor Magnus Rakvåg, Richard Simpson, Antonio Landolfi, Troy Campbell, Kacper Donat, Ivan Zlatev, Trevor Sullivan, Pal Lockheart and 65 more
Reacted by Mitch Ullman, Rain Sallow (/u/ta11ow), Henrik Jensen, fluffninja, Xiang ZHU, Astra Midnight, Param Siddharth and Chris Rivers
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.
Reacted by ExE Boss, masterflitzer, Şafak Gür and Mr Beedell, Roke Julian Lockhart
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.
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.
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.
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.
Activity
MaximoTrinidad commentedon Feb 28, 2017
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.
:)
SteveL-MSFT commentedon Mar 1, 2017
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.
pcgeek86 commentedon Apr 7, 2017
This functionality would be useful to work around #3506.
123 remaining items
bergmeister commentedon Feb 9, 2024
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/
agowa commentedon Feb 9, 2024
Only client versions of windows. What is with servers?
charltonstanley commentedon Mar 27, 2024
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 -swill read the$SHELLenvironment variable to determine what shell to use to execute the command. I changed it to point topwshand that seems to work for my current need of moving a file.However, if I append
-Confirm:$falseto theMove-Itemcmdlet, I get the following error:So this kinda works for using
sudoagainst some simple cmdlets on Linux, but for more complex commands you will definitely get unexpected results. YMMW. Use with caution.GlacierFox commentedon Jul 17, 2024
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.
SeeminglyScience commentedon Mar 24, 2025
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.
microsoft-github-policy-service commentedon Mar 26, 2025
This issue has been marked as declined and has not had any activity for 1 day. It has been closed for housekeeping purposes.
microsoft-github-policy-service commentedon Mar 26, 2025
📣 Hey Joey Aiello (@joeyaiello), how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback