테스트를 위해 '시작> 실행'대화 상자 (cmd.exe 아님)를 사용하고 있습니다.-EncodedCommand가 사용 된 경우 PowerShell 출력을 리디렉션 할 수 없습니다.
이 잘 작동, 나는
powershell -Command 4+5 > c:\log.txt
는하지만이 작동하지 않는 log.txt에 9 얻을 :
powershell -EncodedCommand IAA1ACsANwAgAA== > c:\log.txt
그래서 내가 어떻게이 경우 출력을 리디렉션 할 수 있습니다?
실험 코드 :
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)
}
아 .. 실제로,>은 PowerShell 연산자입니다. – alex2k8