Commands with Bool ($True/$False) Paramiters do not run within a gsudo session
hossimo opened this issue · 5 comments
Issue Description
I get different results from an elevated Powershell vs a Normal one, this seems to happen when I use a Command that requires a $True or $False parameter.
Steps to Reproduce
- From within a non-elevated powershell I run the command
gsudo Disable-NetAdapter -Name "Ethernet" -Confirm:$False
- This gives the the following error after UAC:
Disable-NetAdapter : Cannot convert 'System.String' to the type 'System.Management.Automation.SwitchParameter'
required by parameter 'Confirm'.
At line:1 char:44
Disable-NetAdapter -Name Ethernet -Confirm:False -Verbose
~~~~~
CategoryInfo : InvalidArgument: (:) [Disable-NetAdapter], ParameterBindingException
FullyQualifiedErrorId : CannotConvertArgument,Disable-NetAdapter
However, if I run the same command from an elevated (obviously without (g)sudo) PowerShell it works correctly:
It almost looks like the gsudo is converting the $False to a string "False"
Screenshots
Context:
- Windows version: Win11 23H2 (Build 22631.3447)
- gsudo version: gsudo v2.4.4 (Branch.tags-v2.4.4.Sha.cf887bf98d5d3d90fc1eebc08c7a277afb50cd19)
Please enclose your command to elevate in single quotes, or even better: in {}
brackets
You will find this information usefull:
https://gerardog.github.io/gsudo/docs/usage/powershell#using-gsudo-scriptblock-syntax
Thanks so much for answering, Typical RTFM for me :)
Thanks again this has been a real help! now I just need to make an alias for !!
Lol, happy to help :)
And btw, don't make an alias for !!
, write gsudo
, press space, and then press tab, for example:
PS C:\> echo something
something
PS C:\> sudo [press tab key]
PS C:\> sudo { echo something } # magic autocomplete
(this requires Import-Module gsudoModule
in your profile )
Amazing! Thanks so much again! I'm so glad this will be in Windows by default. I bounce between Windows, Mac and Debian constantly and this is a huge help for my mental gymnastics.
Microsoft's sudo is like 2019's gsudo. You may still want to run winget install gsudo
;)