As mentioned by others, you need to save the code in a .ps1 file and not .bat.
This line (from Setting Windows PowerShell environment variablesSetting Windows PowerShell environment variables) will do the trick:
$env:Path = $env:Path + ";C:\Users\Brett\Compilers\MinGW\bin" Or even shorter:
$env:Path += ";C:\Users\Brett\Compilers\MinGW\bin"