I\'m running exactly the same script.ps1 file in a Powershell ISE (manually loading the script and pressing F5) and in a Powershell console (executing the script file).
as shown in this Stackoverflow answer to prevent git push to print to STDERR the solution is to call the command witn --porcelain option.
git push
--porcelain
then, calling
git push origin master --porcelain
output goes all to STDOUT