Last active
June 16, 2024 20:11
-
-
Save rkitover/46528a07ea013023c3a5aa43b325c1ba to your computer and use it in GitHub Desktop.
PowerShell sudo hack for Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This requires localadmin and pwsh/winps as your ssh shell. | |
function global:sudo { | |
$cmd = [management.automation.invocationinfo].getproperty('ScriptPosition', | |
[reflection.bindingflags] 'instance, nonpublic').getvalue($myinvocation).text -replace '^\s*sudo\s*','' | |
ssh localhost -- "sl '$(get-location)'; $cmd" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment