Question: I have one big batch script which sets bunch of environment variables. 
I want to call that batch script from powershell, that way I can get benefits of both i.e. enviorment variable set by my script and powershell.

Answer: 
If you grab the [PowerShell Community Extensions](https://github.com/Pscx/Pscx), there is an Invoke-BatchFile command in it that runs the batch file but more importantly, it retains any environment variable modifications made by the batch file e.g.:

```
>Invoke-BatchFile 'C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat'
Setting environment for using Microsoft Visual Studio 2008 x86 tools.

```
@Roman Kuzmin's solution works great, but piping the command output to nul can kind of leave you in the dark. So I made a few tweaks to allow for the command output to display normally, and instead pipe the env vars to a temp file to read in afterwards:

```bsh
param
(
    [Parameter(Mandatory=$true)] [string]
    $Command
)
$VarsPath = [IO.Path]::GetTempFileName()
cmd /c "$Command && set > $VarsPath"
if (-not $LASTEXITCODE) {
    Get-Content $VarsPath | ForEach-Object {
        if ($_ -match '^([^=]+)=(.*)') {
            [System.Environment]::SetEnvironmentVariable($matches[1], $matches[2])
        }
    }
}
Remove-Item $VarsPath

```