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).
Hmmm, the only major difference I can think of right off the top of my head is that the ISE uses single-threaded apartment (STA) mode in v2, and the console uses multi-threaded apartment (MTA). Have you tried running powershell.exe with the -STA argument, or powershell_ise.exe with -MTA, and trying the script again?
It looks like the error is coming from the Git command you're trying to run, FWIW.