Getting Help for Cmdlet Parameters

by Nov 3, 2016

There seems to be a bug in PowerShell 5.0 that limits the usefulness of the built-in help window. Whenever you run Get-Help with -ShowWindow, the window just shows the cmdlet syntax and examples. A lot of additional information is missing.

To get detailed information about the parameters a cmdlet supports, ask for this information directly. This line would help explain what the -Format parameter in Get-Date does:

 
PS C:\> Get-Help -Name Get-Date -Parameter Format

-Format []
    Displays the date and time in the Microsoft .NET Framework format indicated by the 
    format specifier. Enter a format specifier. For a list of available format 
    specifiers, see DateTimeFormatInfo Class 
    (http://msdn.microsoft.com/library/system.globalization.datetimeformatinfo.aspx) 
    in MSDN.
    
    When you use the Format parameter, Windows PowerShell gets only the properties of 
    the DateTime object that it needs to display the date in the format that you 
    specify. As a result, some of the properties and methods of DateTime objects might 
    not be available.
    
    Starting in Windows PowerShell 5.0, you can use the following additional formats 
    as values for the Format parameter.
    
    -- FileDate. A file or path-friendly representation of the current date in local 
    time. It is in the form of yyyymmdd ( using 4 digits, 2 digits, and 2 digits). An 
    example of results when you use this format is 20150302.
    
    -- FileDateUniversal. A file or path-friendly representation of the current date 
    in universal time. It is in the form of yyyymmdd + 'Z' (using 4 digits, 2 digits, 
    and 2 digits). An example of results when you use this format is 20150302Z.
    
    -- FileDateTime. A file or path-friendly representation of the current date and 
    time in local time, in 24-hour format. It is in the form of yyyymmdd + 'T' + 
    hhmmssmsms, where msms is a four-character representation of milliseconds. An 
    example of results when you use this format is 20150302T1240514987.
    
    -- FileDateTimeUniversal. A file or path-friendly representation of the current 
    date and time in universal time, in 24-hour format. It is in the form of yyyymmdd 
    + 'T' + hhmmssmsms, where msms is a four-character representation of milliseconds, 
    + 'Z'. An example of results when you use this format is 20150302T0840539947Z.
    
    Required?                    false
    Position?                    named
    Default value                none
    Accept pipeline input?       false
    Accept wildcard characters?  false
 

With this information, you know now how to format date and time:

$date = Read-Host -Prompt 'Enter a date'
$weekday = Get-Date -Date $date -Format 'dddd'
"$date is a $weekday"

Twitter This Tip! ReTweet this Tip!