Skip to content

Instantly share code, notes, and snippets.

@JohnLBevan
Created March 17, 2018 16:27
Show Gist options
  • Select an option

  • Save JohnLBevan/1042571860741781e55e8e135f15bbc7 to your computer and use it in GitHub Desktop.

Select an option

Save JohnLBevan/1042571860741781e55e8e135f15bbc7 to your computer and use it in GitHub Desktop.
Path environment variable too long; trim down some of the SQL entries by replacing with other environment variables...
cls
[Environment]::SetEnvironmentVariable("MSSQL64",'C:\Program Files\Microsoft SQL Server',"Machine")
[Environment]::SetEnvironmentVariable("MSSQL86",'C:\Program Files (x86)\Microsoft SQL Server',"Machine")
$path = [Environment]::GetEnvironmentVariable("PATH","User")
$path = ($path -replace 'C:\\Program Files\\Microsoft SQL Server\\','%MSSQL64%\') -replace 'C:\\Program Files \(x86\)\\Microsoft SQL Server\\','%MSSQL86%\'
[Environment]::SetEnvironmentVariable("PATH",$path,"User")
$path = [Environment]::GetEnvironmentVariable("PATH","Machine")
$path = ($path -replace 'C:\\Program Files\\Microsoft SQL Server\\','%MSSQL64%\') -replace 'C:\\Program Files \(x86\)\\Microsoft SQL Server\\','%MSSQL86%\'
[Environment]::SetEnvironmentVariable("PATH",$path,"Machine")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment