19 lines
560 B
PowerShell
19 lines
560 B
PowerShell
|
function smartsudo() {
|
||
|
[CmdletBinding(SupportsShouldProcess)]param(
|
||
|
[switch]$sudo,
|
||
|
[switch]$Force,
|
||
|
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
|
||
|
[string[]]$expr
|
||
|
)
|
||
|
|
||
|
if( $sudo -and -not $(Test-IsAdmin) ) {
|
||
|
Write-Verbose "Perofrming the following command line via SUDO:`n$($expr -join ' ')"
|
||
|
$local:base64command = ConvertTo-Base64 "$expr"
|
||
|
/usr/bin/env sudo pwsh -EncodedCommand $base64command
|
||
|
return
|
||
|
}
|
||
|
|
||
|
Write-Verbose "Perofrming the following expression in-line:`n$($expr -join ' ')"
|
||
|
Invoke-Expression "$expr"
|
||
|
}
|