Powershell script tips


Write to a file

Use Set-Content and Add-Content

[sourcecode language="bash"]
Set-Content "C:\Program Files\Sublime Text 2\subl.bat" "@echo off"
Add-Content "C:\Program Files\Sublime Text 2\subl.bat" "sublime_text.exe %1"
[/sourcecode]

Adding to environmental path variable

from http://softwaresalariman.blogspot.co.uk/2008/01/add-path-environment-variable-in.html

[sourcecode language="bash"]
Set-Content "C:\Program Files\Sublime Text 2\subl.bat" "@echo off"
Add-Content "C:\Program Files\Sublime Text 2\subl.bat" "sublime_text.exe %1"
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";C:\Program Files\Sublime Text 2", "Machine")
[/sourcecode]