Here is a great response to the red888 script:
function Reload { $CurrentFile = $psise.CurrentFile $FilePath = $CurrentFile.FullPath $lineNum = $psise.CurrentFile.Editor.CaretLine $colNum = $psise.CurrentFile.Editor.CaretColumn $PsISE.CurrentPowerShellTab.Files.remove($CurrentFile) > $null $newFile = $PsISE.CurrentPowerShellTab.Files.add($FilePath) $newfile.Editor.SetCaretPosition($lineNum,$colNum) } $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Clear() $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Reload File",{Reload},'f4') > $null
It restores the position of the carriage after a reboot. I deleted the line
iex $PsISE.CurrentPowerShellTab.Files.Editor.Text
Since I do not need this, and it also does not coincide with running the script (and therefore leads to strange behavior of operators like $script:MyInvocation.MyCommand.Path ).
By the way, if you put this code in your ISE profile, it will automatically run the first time ISE boots up. An ISE profile is just a powershell script whose location is set by the $profile variable.
Here are a few commands that create a profile if it does not exist, and then opens it. Run it from within ISE:
if (!(Test-Path (Split-Path $profile))) { mkdir (Split-Path $profile) } ; if (!(Test-Path $profile)) { New-Item $profile -ItemType file } ; notepad $profile
source share