Getting Help for Objects – Online

by Jan 9, 2013

In PowerShell 3.0, you finally can extend object types dynamically without having to write and import ps1xml-files. Here is an especially useful example:

PS> $code = {
    $url = 'http://msdn.microsoft.com/en-US/library/{0}(v=vs.80).aspx' -f $this.GetType().FullName
    Start-Process $url
}

PS> Update-TypeData -MemberType ScriptMethod -MemberName GetHelp -Value $code -TypeName System.Object

Once you execute this code, every single object has a new method called GetHelp(), and when you call it, your browser will open and show the MSDN documentation page for it – provided the object you examined was created by Microsoft, of course. There are many ways how you can call GetHelp(), for example:

PS> $thedate = Get-Date
PS> $thedate.GetHelp()        # <- opens browser with MSDN help for DateTime data type
PS> (Get-Date).GetHelp()      # <- opens browser with MSDN help for DateTime data type

Twitter This Tip! ReTweet this Tip!