Differences between the PowerShell_ise.exe and PowerShell.exe

From here
  1. Limited support for interactive console apps, try cmd.exe, then try cmd.exe /k
    1. cmd.exe /c dir still works though, and more information is available here
  2. Console Application output is not colorful
  3. STA by default
    1. Try $host.Runspace.ApartmentState
    2. powershell is MTA by default (ApartmentState shows up as Unknown) but can be started in sta mode with powershell -sta.
    3. ISE is always STA
  4. No support for the [Console] class, try [console]::BackgroundColor  = ‘white’.
    1. In general, scripts should use the host API’s (write-host, instead of the [Console] class, so that they work in both the console, ISE, Remoting and other shells.
  5. Limited (close to zero) support on $host.UI.RawUI. We only support the colors and title
    1. The colors are better set in $psISE.Options, because you can set those to any color, not just console colors
  6. Custom/dead-simple more. See gc function:more
    1. The ISE has no pager
  7. Start-Transcript does not work in the ISE
  8. Some Thread Culture differences
    1. If you’re in a non-console supported culture (eg Arabic) ISE will have Get-Culture as ar-sa, and powershell.exe will have Get-Culture as en-us (or some other fallback)
  9. Suggestions dont work in the ISE
    1. For example, in C:\Program Files\Internet Explorer" if you execute iexplore.exe
    2. You’ll only see this in PowerShell.exe
      Suggestion [3,General]: The command iexplore.exe was not found, but does exist in the current location. Windows PowerShe
      ll doesn’t load commands from the current location by default. If you trust this command, instead type ".\iexplore.exe".
      See "get-help about_Command_Precedence" for more details.
  10. The ISE runs a different profile
    1. The ISE profile is in Microsoft.PowerShellISE_profile.ps1, and powershell is in Microsoft.PowerShell_profile.ps1
    2. http://msdn.microsoft.com/en-us/library/bb613488(VS.85).aspx
    3. http://www.leeholmes.com/blog/TheStoryBehindTheNamingAndLocationOfPowerShellProfiles.aspx
    4. You can use the common profile, stored in $profile.CurrentUserAllHosts to make it run in both shells
  11. Only the ISE has $psISE
    1. it gets access to http://psisecream.codeplex.com/, and http://blogs.msdn.com/powershell/archive/2008/12/29/powershell-ise-can-do-a-lot-more-than-you-think.aspx
  12. There could be others, but parity with PowerShell is a big thing for the ISE.

Ibrahim Abdul Rahim



Debugging PowerShell Script Using the ISE Editor


Hi writers and consumers of buggy scripts.
This post explains the basics of the Graphical Debugger in the ISE. There’s a lot of good stuff, with some tips and tricks.
The debugger support got the cmdlets and user interface.  The cmdlets include  Enable/Disable/Get/Set/Remove-PsBreakpoint and Get-PsCallStack.
The general feel is to place breakpoints across the script, continue (F5) to jump from breakpoint to breakpoint, and step over, step into, and step out to move around. You can also get the call stack, and hover over variables to get their values.
Line breakpoints are easy to add, with F9 or context menu (Enable Breakpoint) on any script. However they can only be added to saved scripts. So if you have untitled.ps1, please save it to “powershellmademesaveyou.ps1” first. psm1 files also work. Lots of types of lines can have breakpoints, I’ve seen them work in for each loops, in script blocks, in if and else blocks, in traps, and so on.
Special breakpoints can be added using Set-PSBreakpoint (alias “sbp”). For example, “sbp -command write-error” will take you to the command whenever it executes, and “sbp -variable servername” will stop when $servername is set (or accessed). Theses breakpoints are not displayed on screen, and need to be enabled/removed using the cmdline.
Go to Debug->List Breakpoints to see a list of them.
They can also easily be removed through the context menu, or F9 (or the debug menu, or remove-psbreakpoint cmdlet…)
Breakpoints can also be added when the debugger breaks, but you can’t add a breakpoint while the script is busy running.
Navigation and Exploration
Navigating and exploring is smooth in the ISE. To jump from breakpoint to breakpoint, use Continue (F5). To step over, press F10, step into, F11, and step out, Shift-F11. It’s easy to add more breakpoints while navigating, so you can use that to jump around.
The ISE will automatically open the script that the function you called came from.
Once you’re at an interesting spot, you can:
-          Hover over a variable to see its value. This is a very quick way to see what’s going on
-          Execute a selection using F6. You can execute the if-block condition to see the results. You can execute part of a line in your script, instead of the whole thing.
-          Execute a command in the command pane. You can try out complicated expressions with everything set up. You can also modify variable values here.
-          Get the call stack (Ctrl-Shift-D) to see how deep in trouble you are
-          Get Help on a cmdlet, by selecting it with your mouse and pressing F1
It might also be a good time to stop debugging (Shift-F5) and restart. Scripts are locked during debugging, so you need to stop debugging to continue editing your scripts.
Fun ISE Extensions for debugging
-          Get Last exception
o   $psISE.CustomMenu.Submenus.Add(‘Show Exception’, {$error[$Error.Count – 1].Exception | fl -f *}, "Ctrl+Shift+E")
-          Dump selection info
o   $psISE.CustomMenu.Submenus.Add(‘Get-Member’, {iex $psISE.CurrentOpenedFile.Editor.SelectedText | gm | ft; iex $psISE.CurrentOpenedFile.Editor.SelectedText | fl -f *; }, "Ctrl+D")
-          Go to definition
o   function GotoDefinition($commandName)
    $command = gcm -CommandType Function $commandName
    $file = $command.ScriptBlock.File
    $position = $command.ScriptBlock.StartPosition
    $runspace = $psISE.CurrentOpenedRunspace
    ($runspace.OpenedFiles | ?{$_.FullPath -eq $file}).Editor.SetCaretPosition($position.StartLine, $position.StartColumn)
$psISE.CustomMenu.Submenus.Add("GotoDefinition", {GotoDefinition $psISE.CurrentOpenedFile.Editor.SelectedText}, "Ctrl+Shift+G")
GotoDefinition won’t work until the functions are defined, but you can customize it to do more