Private/SudoPwsh.ps1
function SudoPwsh { [CmdletBinding()] Param( [Parameter(Mandatory=$True)] [string]$CmdString ) $Bytes = [System.Text.Encoding]::Unicode.GetBytes($CmdString) $EncodedCommand = [Convert]::ToBase64String($Bytes) $EncCmdOutput = sudo pwsh -EncodedCommand $EncodedCommand $IndexOfOutputFlag = $EncCmdOutput.IndexOf($($EncCmdOutput | Where-Object {$_ -match '^OutputStartsBelow'})) $StartIndex = $IndexOfOutputFlag+2 $EndIndex = $EncCmdOutput.Count-1 $JsonOutput = $EncCmdOutput[$StartIndex..$EndIndex] try { $Result = $JsonOutput | ConvertFrom-Json [pscustomobject]@{ OutputType = "Success" Output = $Result } } catch { [pscustomobject]@{ OutputType = "Error" Output = $JsonOutput } } } |