Use powershell to quickly set the environment variables on Windows

Instead of doing these steps in this screenshot

Set Windows Machine Environment Variable By CLI

you can run one command in CMD to achieve the same goal

powershell [System.Environment]::SetEnvironmentVariable('ANT_HOME', 'C:\tools\apache-ant-1.9.4\bin', 'Machine')

  • Set variable ANT_HOME
  • to Value C:\tools\apache-ant-1.9.4\bin
  • at Machine level



powershell script to open web address URL with default browser

After install a website, we used to open the start page in web browser.

There are at least (not 2) 4 ways to open web address URL with default browser in Powershell.

1. Run a exe file with parameter is our url.

How to get exe filepath of default browser? define and use this function (thanks to Ravikanth Chaganti):

Function GET-DefaultBrowserPath {
#Get the default Browser path
New-PSDrive -Name HKCR -PSProvider registry -Root Hkey_Classes_Root | Out-Null
$browserPath = ((Get-ItemProperty ‘HKCR:\http\shell\open\command’).'(default)’).Split(‘”‘)[1]
return $browserPath



in my computer Powershell console will return D:\Program Files (x86)\Mozilla Firefox\firefox.exe

2. Simple way:


start ‘’

in Powershell.

Thanks Dac Thach, I tested your solutions and it works on Windows 2008 + Powershell 1.0

3. One another is we use Invoke-Expression

to lend the Windows’ CMD hand (like you open Windows Run / cmd / then type start)


Invoke-Expression “cmd.exe /C start
Invoke-Expression “cmd.exe /C start
Invoke-Expression “cmd.exe /C start /b’&’thach=2+g~

4. Use .NET static function