Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Last active April 8, 2018 02:28
Show Gist options
  • Save Jaykul/3cd196e7000031e78ca9dae872dfc080 to your computer and use it in GitHub Desktop.
Save Jaykul/3cd196e7000031e78ca9dae872dfc080 to your computer and use it in GitHub Desktop.
Get a list of commands with a short synopsis of their functionality

When you first install a module, you usually run a command something like Get-Command -Module newModule to see what commands are available, right?

Well, this function is what I have been running. It still gives you the list of commands from the module, but with the help synopsis next to each one so you can see a little more about what they do. Here are a couple of examples, to encourage you to try it out:

Get-ModuleHelp Microsoft.PowerShell.Archive

Name             Synopsis
----             --------
Compress-Archive Creates an archive, or zipped file, from specified files and folders.
Expand-Archive   Extracts files from a specified archive (zipped) file.
Get-ModuleHelp Configuration

Name                   Synopsis
----                   --------
Get-ManifestValue      Reads a specific value from a PowerShell metdata file (e.g. a module manifest)
Get-StoragePath        Gets an storage path for configuration files and data
Update-Manifest        Update a single value in a PowerShell metadata file
Add-MetadataConverter  Add a converter functions for serialization and deserialization to metadata
ConvertFrom-Metadata   Deserializes objects from PowerShell Data language (PSD1)
ConvertTo-Metadata     Serializes objects to PowerShell Data language (PSD1)
Export-Configuration   Exports a configuration object to a specified path.
Export-Metadata        Creates a metadata file from a simple object
Get-ConfigurationPath  Gets an storage path for configuration files and data
Get-Metadata           Reads a specific value from a PowerShell metdata file (e.g. a module manifest)
Import-Configuration   Import the full, layered configuration for the module.
Import-Metadata        Creates a data object from the items in a Metadata file (e.g. a .psd1)
Test-PSVersion         Test the PowerShell Version
Update-Metadata        Update a single value in a PowerShell metadata file
Update-Object          Recursively updates a hashtable or custom object with new values

However, there's a better way

My new method involves adding a couple of properties to the command info class in my profile:

Update-TypeData -TypeName System.Management.Automation.CommandInfo -MemberName Syntax -Value { 
    ($this | Get-Command -Syntax | Out-String).Trim()
} -MemberType ScriptProperty 

Update-TypeData -TypeName System.Management.Automation.CommandInfo -MemberName Synopsis -Value {
    ($this | Get-Help).Synopsis.Trim()
} -MemberType ScriptProperty 

And now I can get the same help by just formatting:

Get-Command -Module Microsoft.PowerShell.Archive | Format-Table Name, Synopsis

But I can also choose to add more information and (for instance), build useful reference pages for your commands:

Get-Command -Module Microsoft.* | Sort ModuleName | Select ModuleName, Verb, Noun, Name, Synopsis | 
    ConvertTo-Html -PostContent '<script src="https://cdn.rawgit.com/stevesouders/5952488/raw/activetable.js"></script>' | 
    Set-Content MicrosoftCommands.html
function Get-ModuleHelp {
<#
.SYNOPSIS
Get all the commands from a (set of) module(s), with a short synopsis of their functionality
.DESCRIPTION
Runs Get-Command and Get-Help against all the commands in the specified module(s), and outputs the results in a way that makes it easy to examine and decide which commands you need from a new module. Note that running Get-Help generally imports the module, so you should take care.
Never install a module you don't trust into your PowerShell module path.
.EXAMPLE
Get-ModuleHelp Microsoft.* | Sort ModuleName | Format-Table -Group ModuleName
Lists the commands from multiple modules, grouped by module, with a synopsis
.EXAMPLE
Get-ModuleHelp * | Sort ModuleName |
Select ModuleName, Verb, Noun, Name, Synopsis |
ConvertTo-Html -PostContent '<script src="https://cdn.rawgit.com/stevesouders/5952488/raw/activetable.js"></script>' |
Set-Content MicrosoftCommands.html
Creates an HTML report (with a sortable table) from all of the modules available on your system. This may take awhile to load, but when it's done you'll have a searchable, sortable list of commands, with a short synopsis for each about what it does.
#>
[CmdletBinding()]
param(
# The name of the module to get help for
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[string[]]$Module
)
begin {
$display = [System.Management.Automation.PSPropertySet]::new( "DefaultDisplayPropertySet", [string[]]@("Name", "Synopsis"))
}
process {
Get-Command -Module $Module | Select *, @{ Name = "Synopsis"; Expr = { (Get-Help $_.Name).Synopsis.Trim() }} |
# For display purposes...
Add-Member MemberSet PSStandardMembers $display -Passthru
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment