I have function like this (test.ps1):
function HLS {
Write-Host 'Hello, World!'
}
I execute this commands in PS window:
$expression = Get-Content -Path .\test.ps1
$commandBytes = [System.Text.Encoding]::Unicode.GetBytes($expression)
$encodedCommand = [Convert]::ToBase64String($commandBytes)
powershell -EncodedCommand $encodedCommand
It does not give me any output, which is good because i would need to execute this function. After trying to execute this command:
PS C:\truncated> HLS
It gives me error:
HLS : The term 'HLS' is not recognized as the name of a cmdlet, function, script file, or operable program.
Does anyone know how to execute function that is passed as -EncodedCommand parameter?
.\test.ps1?? By runningpowershell -EncodedCommand $encodedCommand, the script will use its own environment and the caller script will have no knowledge about that.$expression = Get-Content -Path .\test.ps1