powershell script to edit profile
For the record, I've been playing with powershell for about a week now, and I fucking love it.
Check out my latest function, I am so awesome.
Useful for adding to your profile
(if you haven't rtfm'd, then: new-item $profile -itemType file; notepad $profile. The rest is up to you)
Anyway, it brings up my favorite editor (notepad2), and re-starts powershell (using a path to my own local shortcut) but -- and here's the cool bit -- only if you actually changed your profile
# Launches an editor for this file, and re-starts
# powershell if changes were made
function pro {
#make a backup file
cp $profile ($profile + ".bak")
# piping (non-existant) output makes script wait for exit
&"c:\Program Files\notepad2\Notepad2.exe" $profile | out-null
# If user made changes, re-launch shell. otherwise do nothing
$old = get-content $profile
$new = get-content ($profile + ".bak")
if ($null -ne (
Compare-Object -ReferenceObject $new -differenceobject $old
)
) {
rm ($profile + ".bak")
# user exited editor, re-start powershell
&"C:\Documents and Settings\All Users\Start Menu\Windows PowerShell.lnk"
# quit this particular shell
exit
}
rm ($profile + ".bak")
}