Für meine Tests verwende ich den Dialog 'Start> Ausführen' (nicht die cmd.exe).PowerShell-Ausgabe kann nicht umgeleitet werden, wenn -EncodedCommand verwendet wurde
Dies funktioniert gut, und ich bekomme 9 in log.txt
powershell -Command 4+5 > c:\log.txt
Aber dies nicht funktioniert:
powershell -EncodedCommand IAA1ACsANwAgAA== > c:\log.txt
So wie kann ich Ausgang in diesem Fall umleiten?
Experimental-Code:
function Test
{
$cmd = { 5+7 }
$encodedCommand = EncodeCommand $cmd
StartProcess "powershell -Command $cmd > c:\log.txt"
StartProcess "powershell -EncodedCommand $encodedCommand > c:\log2.txt"
}
function StartProcess($commandLine)
{
Invoke-WMIMethod -path win32_process -name create -argumentList $commandLine
}
function EncodeCommand($expression)
{
$commandBytes = [System.Text.Encoding]::Unicode.GetBytes($expression)
[Convert]::ToBase64String($commandBytes)
}
Ah .. Tatsächlich ist das> nur ein PowerShell-Operator. – alex2k8