g++ test.cpp -o test 2>> error.txt g++ test.cpp -o test 2>&1 | Tee-Object -Filepath error.txtinvoke-command { 'txt1'; write-error 'err'; 'txt2' } -ErrorVariable e
#пример вызова внешней команды
invoke-command { python 1.py 2>&1 } -ErrorVariable e
$e | Out-File error.txt