Created
December 9, 2022 19:43
-
-
Save jonshipman/fe849f7ce841a84be48ee168606771d6 to your computer and use it in GitHub Desktop.
sudo implementation for powershell
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
# Place this function in you $Env:Profile | |
# Has worked with most of what I've thrown at it. | |
# E.g. `sudo cmd.exe /C mklink /J C:\Test C:\Windows` | |
function Sudo { | |
[string] $Location = (Get-Location) | |
$NewArgs = @() | |
For ( $i = 0; $i -Lt $args.Length; $i++) { | |
$NewItem = "$($args[$i])".Replace(" ","`` ").Replace("'","``'").Replace('"','``"') | |
If ($NewItem -Match " ") { | |
$NewItem = '"' + $NewItem + '"' | |
} | |
$NewArgs = $NewArgs + $NewItem | |
} | |
pwsh -Command "Start-Process pwsh -Verb RunAs -WorkingDirectory '$Location' -ArgumentList '-Command', '$NewArgs'" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment