Skip to content

Instantly share code, notes, and snippets.

@marckassay
Last active August 26, 2017 18:39
Show Gist options
  • Save marckassay/ef18b2e0fbc03a479f06ccc20f6bf25d to your computer and use it in GitHub Desktop.
Save marckassay/ef18b2e0fbc03a479f06ccc20f6bf25d to your computer and use it in GitHub Desktop.
Get-ModuleSynopsis - Lists all available functions for a module, with the synopsis of those functions.
<#
.SYNOPSIS
Lists all available functions for a module, with the synopsis of the functions.
.DESCRIPTION
Lists all available functions of a module using Get-Command and Get-Help.
.PARAMETERS
Name <String> The name of the module installed.
.INPUTS
None
.OUTPUTS
PSCustomObject
.EXAMPLE
E:\> Get-ModuleSynopsis Microsoft.PowerShell.Utility
Name Synopsis
---- --------
ConvertFrom-SddlString
Format-Hex Displays a file or other input as hexadecimal.
Get-FileHash Computes the hash value for a file by using a specified hash algorithm.
Import-PowerShellDataFile
New-Guid Creates a GUID.
New-TemporaryFile Creates a temporary file.
Add-Member Adds custom properties and methods to an instance of a Windows PowerShell object.
Add-Type Adds a.NET Framework type (a class) to a Windows PowerShell session.
#>
function Get-ModuleSynopsis
{
[CmdletBinding(PositionalBinding=$False)]
Param(
# Any other parameters can go here
)
DynamicParam {
# Set the dynamic parameters' name
$ParameterName = 'Name'
# Create the dictionary
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
# Create the collection of attributes
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
# Create and set the parameters' attributes
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
$ParameterAttribute.Mandatory = $True
$ParameterAttribute.Position = 0
# Add the attributes to the attributes collection
$AttributeCollection.Add($ParameterAttribute)
# Generate and set the ValidateSets
$NonInstalledSet = Get-Module | Select-Object -ExpandProperty Name
$InstalledSet = Get-InstalledModule | Select-Object -ExpandProperty Name
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($NonInstalledSet + $InstalledSet)
# Add the ValidateSet to the attributes collection
$AttributeCollection.Add($ValidateSetAttribute)
# Create and return the dynamic parameter
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
return $RuntimeParameterDictionary
}
begin {
# Bind the parameter to a friendly variable
$Name = $PsBoundParameters[$ParameterName]
}
process {
Get-Command -Module $Name | Foreach-Object {
$Syno = Get-Help -Name $_.Name | Select-Object -ExpandProperty Synopsis
[PSCustomObject]@{
Name = $_.Name
Synopsis = $Syno }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment