Creating PowerShell Command Cheat Sheets (Part 4)

by May 16, 2018

In the previous tip, we created cheat sheets for PowerShell commands. We used command names and their synopsis to create cheat sheets like this:

 
PS> Get-Command -Module "PrintManagement"| 
  Get-Help | 
  Select-Object -Property Name, Synopsis

Name                   Synopsis                                             
----                   --------                                             
Add-Printer            Adds a printer to the specified computer.            
Add-PrinterDriver      Installs a printer driver on the specified computer. 
Add-PrinterPort        Installs a printer port on the specified computer.   
Get-PrintConfiguration Gets the configuration information of a printer.     
Get-Printer            Retrieves a list of printers installed on a computer.
Get-PrinterDriver      Retrieves the list of printer drivers installed on...
Get-PrinterPort        Retrieves a list of printer ports installed on the...
Get-PrinterProperty    Retrieves printer properties for the specified pri...
Get-PrintJob           Retrieves a list of print jobs in the specified pr...
Read-PrinterNfcTag     Reads information about printers from an NFC tag.    
Remove-Printer         Removes a printer from the specified computer.       
Remove-PrinterDriver   Deletes printer driver from the specified computer.  
Remove-PrinterPort     Removes the specified printer port from the specif...
Remove-PrintJob        Removes a print job on the specified printer. 
... 

There are many more useful properties in the objects returned by Get-Help, like “description” and “examples”. They look strange, though, as if they were embedded in a hash table:

 
PS> Get-Command -Module "PrintManagement"| 
  Get-Help | 
  Select-Object -Property Name, Description 

Name                   description                                                                
----                   -----------                                                                
Add-Printer            {@{Text=The Add-Printer cmdlet adds a printer to a specified computer. Y...
Add-PrinterDriver      {@{Text=The Add-PrinterDriver cmdlet installs a printer driver on the sp...
Add-PrinterPort        {@{Text=The Add-PrinterPort cmdlet creates a printer port on the specifi...
Get-PrintConfiguration {@{Text=The Get-PrintConfiguration cmdlet gets the configuration informa...
Get-Printer            {@{Text=The Get-Printer cmdlet retrieves a list of printers installed on...
Get-PrinterDriver      {@{Text=The Get-PrinterDriver cmdlet retrieves the list of printer drive...
Get-PrinterPort        {@{Text=The Get-PrinterPort cmdlet retrieves a list of printer ports tha...
Get-PrinterProperty    {@{Text=The Get-PrinterProperty cmdlet retrieves one or more printer pro...
Get-PrintJob           {@{Text=The Get-PrintJob cmdlet retrieves the current print jobs in the ...
Read-PrinterNfcTag     {@{Text=The Read-PrinterNfcTag cmdlet reads information about printers f...
Remove-Printer         {@{Text=The Remove-Printer cmdlet deletes a printer from the specified c...
Remove-PrinterDriver   {@{Text=The Remove-PrinterDriver cmdlet deletes a printer driver from th...
Remove-PrinterPort     {@{Text=The Remove-PrinterPort cmdlet removes the specified printer port...
...

This is because properties like “Description” contain a property called “Text” which is an array (allowing multi-line text). To get the plain text, you need to manually retrieve the information from the property like so:

# adjust the name of the module
# code will list all commands shipped by that module
# list of all modules: Get-Module -ListAvailable
$ModuleName = "PrintManagement"

$Description = @{
    Name = "Description"
    Expression = { $_.Description.Text -join " " }
}

Get-Command -Module $moduleName | 
  Get-Help | 
  Select-Object -Property Name, $Description

Now the result looks as expected:

 
Name                   Description                                             
----                   -----------                                             
Add-Printer            The Add-Printer cmdlet adds a printer to a specified ...
Add-PrinterDriver      The Add-PrinterDriver cmdlet installs a printer drive...
Add-PrinterPort        The Add-PrinterPort cmdlet creates a printer port on ...
Get-PrintConfiguration The Get-PrintConfiguration cmdlet gets the configurat...
Get-Printer            The Get-Printer cmdlet retrieves a list of printers i...
Get-PrinterDriver      The Get-PrinterDriver cmdlet retrieves the list of pr...
Get-PrinterPort        The Get-PrinterPort cmdlet retrieves a list of printe...
Get-PrinterProperty    The Get-PrinterProperty cmdlet retrieves one or more ...
Get-PrintJob           The Get-PrintJob cmdlet retrieves the current print j...
Read-PrinterNfcTag     The Read-PrinterNfcTag cmdlet reads information about...
Remove-Printer         The Remove-Printer cmdlet deletes a printer from the ...
Remove-PrinterDriver   The Remove-PrinterDriver cmdlet deletes a printer dri...
Remove-PrinterPort     The Remove-PrinterPort cmdlet removes the specified p...
Remove-PrintJob        The Remove-PrintJob cmdlet removes a print job on the...
Rename-Printer         The Rename-Printer cmdlet renames the specified print...
Restart-PrintJob       The Restart-PrintJob cmdlet restarts a print job on t...
Resume-PrintJob        The Resume-PrintJob cmdlet resumes a suspended print ...
Set-PrintConfiguration The Set-PrintConfiguration cmdlet sets the printer co...
Set-Printer            The Set-Printer cmdlet updates the configuration of t...

Twitter This Tip! ReTweet this Tip!