PowerShell has a pretty good built-in help system that I use a lot and I'm able to see all help options with Get-Help *
and query Cmdlets or can look up Topics with Get-Help about_*
and then say Get-Help about_compar*
to open the Comparison Operators topic which is all very good.
However, I was trying to find how to get help on the various string operators, like .replace, .compare, .split, .substring. Does anyone know how to pull these topics up on the PowerShell console (possibly, they might be hidden inside some of the about_* topics, but it's not obvious or clear to me where to look)?
Also, the string operators have -replace, -compare, -split variants etc and while almost the same as the .replace etc, one version uses regular expressions and the other does not. Does anyone know if there are help topics (again, available from the console!) that clarifies all of this? The PowerShell help system will feel quite lacking if it is missing clarifications on all of this in its built-in help system as these are a very heavily used part of the language (so hopefully this is all tucked away in some about_* topics that I've not found yet).
As has been noted, methods of .NET types such as
System.String.Split()
are not part of PowerShell, but of the .NET framework that PowerShell is built on, so you'll have to consult the official documentation at https://learn.microsoft.com.That said, given the close integration between PowerShell and .NET, it would be nice to be able to easily consult this documentation from within PowerShell - see GitHub issue #11338.
However, operators such as
-split
are PowerShell language features, and both discovering their documentation altogether and getting focused, operator-specific information is currently cumbersome.Documentation for language features such as operators is contained in
about_*
help topics, which can be targeted withGet-Help -Category HelpFile
, and you can combine that with passing the (quoted) name of the operator in order to search the contents of these topics:Get-Help -Category HelpFile -Name '-replace'
at least narrows the search down, but still includes all help topics that mention-replace
; the result will comprise the about_Operators help topic, which is the overview page that links to more specific pages focused on specific categories of operators, such as arithmetic operators, comparison operators, ..., but also describes some general-purpose operators directly.There is currently no direct way to get focused information for a given operator, but there should be: see GitHub issue #11339.
Below are two helper functions that try to overcome the current limitations (as of v7.3.0),
Show-OperatorHelp
andShow-TypeHelp
.Note:
Both functions (of necessity) don't show the documentation in the console (terminal), but open the online documentation in your default web browser.
In
Show-TypeHelp
, support is limited to those (public) types that ship with .NET and therefore have documentation pages at https://learn.microsoft.com.Show-OperatorHelp
opens the specific section describing just the operator of interest whenever possible; some operators, such as the arithmetic operators+
,-
, don't have individual sections, but the overall topic is usually short enough in these cases to make it easy to find the parts of interest.They come with comment-based help, so you can use
-?
andGet-Help
to learn more about them.You can place them in your
$PROFILE
file, for instance, or - given their length - you may want to create external scripts (*.ps1) based on them that you place in a directory listed in$env:Path
. To that end, simply strip thefunction <name> {
line and the final}
and save them to a*.ps1
file.Example uses:
Show-OperatorHelp
:Show-TypeHelp
:I suggest getting the source code from the following MIT-licensed Gists instead, as only they will be maintained; assuming you have looked at the code (which I can personally assure you is safe, but you should always check), you can install them directly:
Note: Ignore the broken syntax highlighting below.
Show-OperatorHelp
source code:Show-TypeHelp
source code: