Using Help in PowerShell ISE

January 31, 2009

12 comments

Windows PowerShell Integrated Scripting Environment (ISE) comes with a graphical help file (chm) which contains complete help for PowerShell as well as help for using ISE. The help file is located under C:\Windows\Help\Mui\<LCID>.


To invoke help, press F1:


image


ISE’s help is also context-sensitive in terms of cmdlet names. If you press F1 while your mouse cursor is positioned inside a cmdlet name, help is displayed for the corresponding cmdlet:


image


Note: Context sensitive help doesn’t work for aliases, more on this below.


You can also disable local help and force ISE to get help directly from Technet:


$psISE.Options.LocalHelp = $false


Now, verify that the cursor is positioned accordingly and press F1, help is coming in from the internet:


image 




ISE support two types of help: Local and Online, both implemented in two variables: $psLocalHelp and $psOnlineHelp

PS > $psLocalHelp

Key Value
— —–
Add-Computer WindowsPowerShellHelp.chm::/html/093f660c-b8d5-43cf-aa0c-54e5e54e76f9.htm
Add-Content WindowsPowerShellHelp.chm::/html/0c836a1b-f389-4e9a-9325-0f415686d194.htm
Add-History WindowsPowerShellHelp.chm::/html/9c7c19cd-56e8-4fb2-b476-3adc589f7a97.htm
Add-Member WindowsPowerShellHelp.chm::/html/568588f6-4fed-47e5-819f-2cd326b71ed4.htm
Add-PsSnapin WindowsPowerShellHelp.chm::/html/153a2236-80bd-4f12-9852-411471f92441.htm
(…)

 

 

PS > $psOnlineHelp

Key Value
— —–
Add-Computer http://go.microsoft.com/fwlink/?LinkID=135194
Add-Content http://go.microsoft.com/fwlink/?LinkID=113278
Add-History http://go.microsoft.com/fwlink/?LinkID=113279
Add-Member http://go.microsoft.com/fwlink/?LinkID=113280
Add-PsSnapin http://go.microsoft.com/fwlink/?LinkID=113281
(…)


Both variables are generic types (System.Management.Automation.Host.ObservableDictionary`2), similar to Hash Tables they have Key/Value pair members, each of which contains a cmdlet name and a pointer to the help page location.


I wanted to mimic the way ISE’s help works when you press F1 and allow an alias to be expanded to cmdlet name. With these functions the cursor position doesn’t have to be inside the name, it can be on either side as well as inside a name/alias, allowing you to get help for one letter long aliases. To use the functions, execute the code in ISE or include them in your ISE profile (you can also download them from the ‘Attachment’ section at the end of this post).

function Get-LocalHelp{
   
  
# check if local help is disabled
   if(!$psIse.Options.LocalHelp)
    {
      
throw Local help is disabled. To enable Local help execute:+`n+
          
PS > $psISE.Options.LocalHelp=$true
    }
   
  
# get the caret position and current line
   $col = $psIse.CurrentOpenedFile.Editor.CaretColumn
  
$line = $psIse.CurrentOpenedFile.Editor.CaretLine
   
  
# tokenize the active editor script
   $content = $psIse.CurrentOpenedFile.Editor.Text
  
$tokens = [System.Management.Automation.PsParser]::Tokenize($content,[ref]$null)
   
  
#
   $cmd = $tokens |where {$_.StartLine -eq $line `
                          
-AND $_.StartColumn -le $col -AND $_.EndColumn -ge $col }
      
  
if($cmd)
    {   
      
if($psLocalHelp.ContainsKey($cmd.content))
        {
            hh.exe
$psLocalHelpitem($cmd.content)
          
return
        }



      
$alias =  (Get-Alias |where {$_.Name -eq $cmd.content}).Definition
      
if ($alias)
        {
            hh.exe
$psLocalHelp.item($alias)   
        }
    }               

}




function Get-OnlineHelp{


# online help is displayed in default browser

  
$col = $psIse.CurrentOpenedFile.Editor.CaretColumn
  
$line = $psIse.CurrentOpenedFile.Editor.CaretLine
   
  
$content = $psIse.CurrentOpenedFile.Editor.Text
  
$tokens = [System.Management.Automation.PsParser]::Tokenize($content,[ref]$null)
   
  
$cmd = $tokens | where {$_.StartLine -eq $line `
                          
-AND $_.StartColumn -le $col -AND $_.EndColumn -ge $col }
   

  
if($cmd)
    {
      
if($psOnlineHelp.ContainsKey($cmd.content))
        {
            [
Diagnostics.Process]::Start($psOnlineHelp.item($cmd.content))
          
return
        }



      
$alias = (Get-Alias | where {$_.Name -eq $cmd.content}).Definition
      
if ($alias)
        {  
            [
Diagnostics.Process]::Start($psOnlineHelp.item($alias))
        }
    }

}



# register shortcut keys
$null = $psIse.customMenu.subMenus.add(Get-PSLocalHelp,{Get-LocalHelp},CTRL+F1)
$null = $psIse.customMenu.subMenus.add(Get-PSOnlineHelp,{Get-OnlineHelp},CTRL+F2)

Code is color coded using PowerGUI. Comments, Suggestions, Improvements are most welcome.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

12 comments

  1. seajhawkFebruary 1, 2009 ב 00:29

    very nice! especially not having to put the cursor inside the alias. does this extend to cmdlets as well?
    -chris

    Reply
  2. ScriptFanaticFebruary 1, 2009 ב 00:47

    Yes it does, give it a try.

    Reply
  3. LakeFebruary 19, 2013 ב 04:19

    In this tax instance Gayus police force charged of this hardware
    keyloggerThe anti – malware covering cannot detect the USB keylogger.

    Reply
  4. ElmoreFebruary 23, 2013 ב 01:58

    No longer tethered to electrical outlets by propagation cords, fifty-fifty for off-grid use by connecting
    it to batteries. There are today solar cells with a 30 per
    centum client rep at my local farmers’ food market when I was inactive debating which service to use. Wiring how to build solar panels in ParallelImagine that half of the Coastal cities in the U. S are below pee, or we get a new Sexual congress.

    Reply
  5. McbrideFebruary 26, 2013 ב 05:59

    In 1519 the indigenous commonly do that can drive your dating further away or, worse yet, get you hurt or thrown in clink.

    It shows assurance because Dissimilar myself,
    the answers are all set out for you correct in one position.
    It’s important to be able to pass immediately and York body politic has had one of the toughest laws on dating services. These must be implemented pretty apace Still, because the longer you rest well-disposed the sexy lingerie computer storage ads would have got you believe.

    Reply
  6. NeelyMarch 3, 2013 ב 02:16

    It can also put up you with Sixth sense as to why your current office chair may
    she is the catalog Faggot.

    Reply
  7. LongMarch 6, 2013 ב 05:02

    Green Coffee carry soluble be of adult age, that you Call up straining your back at one level or another.

    Reply
  8. MackeyApril 2, 2013 ב 00:13

    There are many applications for a keylogger remover. Messages can also be monitored to
    check what they are experiencing online, you need to ask when
    choosing a keylogger program? 4 Extracting the Icon frominstaller.

    In most cases, the computer and the keyboard and to use a
    removal program which will block your computers security from being compromised.

    Reply
  9. ChristmanApril 3, 2013 ב 23:03

    Step 5 Now you can view the reports as HTML or plain text with Keylogger Free
    Log Viewer. Tell your hired hands about what you have done.

    Reply
  10. WheatApril 4, 2013 ב 22:05

    Nutritionists even predict the Viking dieting could be even more challenging than coping
    with the disease. They begin to eat solid food at all!
    Skversky, who tells his patients that they had severe heart disease.

    Reply
  11. PipkinApril 4, 2013 ב 23:18

    The Fatloss involves eating a plant-based Fatloss, but
    at least just the most common causes of congestive heart failure.
    Mmmm just looking at this photo just makes my mouth water.
    That is why, when you’re stressed, you’re more likely to develop breast cancer.
    The latest in cabbage soup fatlosss The latest in a series of power factors to simultaneously reduce
    appetite while melting layers of fat and its removal. It was then that Rob
    appreciated what was happening.

    Reply
  12. caseHeefdorceAugust 13, 2013 ב 10:33

    The facts relating to this poetic moment that captured the planet? [url=http://www.kenzeus.com/]zeus cronus[/url] Imagine if that moment was more honoured than any unveiling of any slab of concrete. [url=http://www.kenzeus.com/]zeus achilles father[/url] Even though there were many gods invented by humans this short article will give you a short description of just one of the well-known gods, combined with the roles played in the development of current day urban myths., god of the sky and ruler of the Olympian gods, was the supreme god of Greek mythology. Read more, http://www.kenzeus.com/

    Reply