Skip to content

Instantly share code, notes, and snippets.

@rkitover
Last active June 16, 2024 20:11
Show Gist options
  • Save rkitover/46528a07ea013023c3a5aa43b325c1ba to your computer and use it in GitHub Desktop.
Save rkitover/46528a07ea013023c3a5aa43b325c1ba to your computer and use it in GitHub Desktop.
PowerShell sudo hack for Windows
# 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