SID-500

Home » PowerShell » PowerShell: Using the Help (Get-Help)

PowerShell: Using the Help (Get-Help)

Don Jones, the author of “Learn PowerShell in a month of lunches” said:

“Be prepared to read the help, or you’ll fail at PowerShell.”


What a great quote.  I´m game with him and I remember his words every time when I forget using the help system for troubleshooting.

Downloading the Help Content

You can call the help with the Cmdlet Get-Help. This gives you the information that help is only available online. But the good news are: You are able to download it.

Get-Help
Unbenannt.PNG

To use help for Get-Childitem without downloading it run

Get-Help Get-ChildItem -Online

Once executed a browser window will appear and show you the help online.

Unbenannt.PNG

Back to the main topic. To download help run

Update-Help -UICulture "en-US" -Force

Please note that you can run the command without -Force only once a day.

Using the Help

Get-Help offers a wide range of parameters. Type Get-Help and then type – and hold CTRL + SPACE to see all of them.
Unbenannt.PNG

To get the help content of Get-Childitem simply type

Get-Help Get-ChildItem 

or

Help Get-ChildItem

This shows the small version of the Help. For beginners it can be frustrating reading the help this way. It offers no examples and no detailed information about the use of the Command. Let´s move on with the Example Parameter, which is more useful for “learning by doing”.

The Examples

The PowerShell Help Examples are really great and excellently suitable for doing your first steps with PowerShell. For getting the examples for Get-ChildItem run

Get-Help Get-ChildItem -Examples

and look for example 6 and example 8.
Unbenannt.PNG

Unbenannt.PNG

Combine them to list all text files in the current directory by name.

Get-ChildItem . -Name -Include *.txt -Recurse -Force

Unbenannt.PNG

Another example shows how to use Powershell Attributes with Get-Date.

Help Get-Date -Online

Scroll down the browser window to the examples section and look for Example 4.

Unbenannt.PNG

Now you can start playing. For example, you can modify the command and fill in your date of birth.

Tip: Type (Get-Date). then Press CTRL + SPACE. Have fun while exploring the attributes of Get-Date.
Unbenannt.PNG

Examples:

(Get-Date -Year 1976 -Month 03 -Date 23).IsDaylightSavingTime()
(Get-Date).AddDays(300)

or search for user which have not logged on to the domain for a year:

Get-ADUser -Filter * -Properties LastLogonDate | ? {$_.lastlogondate -ne $null -and $_.lastlogondate -le ((get-date).adddays(-365))} | Format-List Name,LastLogonDate

or search for inactive mailboxes:

Get-MailboxStatistics -server server01 | ? {$_.lastlogontime -ne $null -and $_.lastlogontime -le ((get-date).adddays(-365))} | Sort-Object {$_.lastlogontime}

The Full Help

To get the full help run

Get-Help Get-Date -Full

The full help displays the whole help topic. This includes parameters, attributes, and last but not least the examples.

The Detailed Help

Get-Help with the parameter Detailed shows parameter descriptions and examples.

Get-Help Get-Date -Detailed

See also

To be faster you can use some tricks to get more out of Parameters: PowerShell Cmdlets: List all availabe parameters without using the Help


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

WHOIS

My name is Patrick Grünauer (pewa2303). I am from Austria. On sid-500 I write about Windows, Cisco and IT-Security in English and German. Have fun while reading!

Patrick Gruenauer
Follow SID-500 on WordPress.com