How to export and import environment variables in windows?

后端 未结 8 1482
粉色の甜心
粉色の甜心 2020-12-22 15:36

I found it is hard to keep my environment variables sync on different machines. I just want to export the settings from one computer and import to other ones.

I thi

8条回答
  •  北海茫月
    2020-12-22 16:04

    Here is my PowerShell method

    gci env:* | sort-object name | Where-Object {$_.Name -like "MyApp*"} | Foreach {"[System.Environment]::SetEnvironmentVariable('$($_.Name)', '$($_.Value)', 'Machine')"}
    

    What it does

    1. Scoops up all environment variables
    2. Filters them
    3. Emits the formatted PowerShell needed to recreate them on another machine (assumes all are set at machine level)

    So after running this on the source machine, simply transfer output onto the target machine and execute (elevated prompt if setting at machine level)

提交回复
热议问题